codice_amministratore ?: $amministratore->codice_univoco ?: '')); if ($code === '') { throw new InvalidArgumentException('Amministratore senza codice archivio canonico.'); } return $code; } public function stabileCode(Stabile | string $stabile): string { if (is_string($stabile)) { $code = trim($stabile); if ($code === '') { throw new InvalidArgumentException('Codice stabile non valido.'); } return $code; } $code = trim((string) ($stabile->codice_stabile ?? '')); if ($code === '') { throw new InvalidArgumentException('Stabile senza codice archivio canonico.'); } return $code; } public function amministratoreRelativePath(Amministratore | string $amministratore, ?string $suffix = null): string { $basePath = 'amministratori/' . $this->amministratoreCode($amministratore); return $this->appendSuffix($basePath, $suffix); } public function amministratoreAbsolutePath(Amministratore | string $amministratore, ?string $suffix = null): string { return storage_path('app/' . $this->amministratoreRelativePath($amministratore, $suffix)); } public function stabileRelativePath(Stabile $stabile, ?string $suffix = null): string { $basePath = $this->amministratoreRelativePath($stabile->amministratore) . '/stabili/' . $this->stabileCode($stabile); return $this->appendSuffix($basePath, $suffix); } public function stabileAbsolutePath(Stabile $stabile, ?string $suffix = null): string { return storage_path('app/' . $this->stabileRelativePath($stabile, $suffix)); } public function fornitoreCode(Fornitore | string $fornitore): string { if (is_string($fornitore)) { $code = trim($fornitore); if ($code === '') { throw new InvalidArgumentException('Codice fornitore non valido.'); } return $code; } $code = trim((string) ($fornitore->codice_univoco ?: '')); if ($code === '') { throw new InvalidArgumentException('Fornitore senza codice archivio canonico.'); } return $code; } public function fornitoreRelativePath(Fornitore | string $fornitore, ?string $suffix = null): string { $basePath = 'fornitori/' . $this->fornitoreCode($fornitore); return $this->appendSuffix($basePath, $suffix); } public function fornitoreAbsolutePath(Fornitore | string $fornitore, ?string $suffix = null): string { return storage_path('app/' . $this->fornitoreRelativePath($fornitore, $suffix)); } public function fornitoreLegacyRelativePath(Fornitore $fornitore, ?string $suffix = null): string { $basePath = $this->amministratoreRelativePath($fornitore->amministratore) . '/fornitori/' . $this->fornitoreCode($fornitore); return $this->appendSuffix($basePath, $suffix); } public function fornitoreLegacyAbsolutePath(Fornitore $fornitore, ?string $suffix = null): string { return storage_path('app/' . $this->fornitoreLegacyRelativePath($fornitore, $suffix)); } private function appendSuffix(string $basePath, ?string $suffix): string { $normalizedSuffix = trim((string) $suffix, '/'); if ($normalizedSuffix === '') { return $basePath; } return $basePath . '/' . $normalizedSuffix; } }