*/ public array $billingUnits = []; private int $nextId = 1; public function findForCustomer(int $customerId, int $billingUnitId): ?BillingUnit { $billingUnit = $this->billingUnits[$billingUnitId] ?? null; return $billingUnit !== null && $billingUnit->customerId() === $customerId ? clone $billingUnit : null; } public function save(BillingUnit $billingUnit): BillingUnit { $id = $billingUnit->id() ?? $this->nextId++; $stored = BillingUnit::reconstitute( $id, $billingUnit->customerId(), $billingUnit->name(), $billingUnit->billingAddress(), $billingUnit->eInvoiceAddress(), $billingUnit->eInvoiceOperator(), $billingUnit->reference(), ); $this->billingUnits[$id] = $stored; return clone $stored; } public function delete(BillingUnit $billingUnit): void { unset($this->billingUnits[$billingUnit->id()]); } }