projects)) { $this->projects = $this->runFactory('projects') ?? []; } return $this->projects; } protected array $brokers; public function brokers(): array { if (empty($this->brokers)) { $this->brokers = $this->runFactory('brokers') ?? []; } return $this->brokers; } protected array $unitTypes; public function unitTypes(): array { if (empty($this->unitTypes)) { $this->unitTypes = $this->runFactory('unitTypes') ?? []; } return $this->unitTypes; } protected array $unitLines; public function unitLines(): array { if (empty($this->unitLines)) { $this->unitLines = $this->runFactory('unitLines') ?? []; } return $this->unitLines; } protected array $units; public function units(): array { if (empty($this->units)) { $this->units = $this->runFactory('units') ?? []; } return $this->units; } public function value(float $price): float { if ($this->type === Type::FIXED) { return $price + $this->amount; } return $price / (1 - $this->amount); } protected function jsonComplement(): array { return [ 'description' => $this->description, 'amount' => $this->amount, 'start_date' => $this->startDate->format('Y-m-d'), 'end_date' => $this->endDate?->format('Y-m-d'), 'valid_until' => $this->validUntil?->format('Y-m-d'), 'type' => $this->type, 'state' => $this->state, 'projects' => $this->projects() ?? [], 'contracts' => $this->brokers() ?? [], 'units' => $this->units() ?? [] ]; } }