$collections */ public function __construct( public readonly string $title, public readonly string $briefing, public readonly string $model, public readonly array $collections, public readonly int $contextLimit, public readonly ?int $authorProfileId, public readonly ?int $contractId, public readonly ?int $structureId, public readonly string $action, ) { } /** * @param array $data */ public static function fromRequest(array $data): self { $collections = $data['collections'] ?? ['documents']; if (!is_array($collections)) { $collections = [$collections]; } return new self( title: trim((string) ($data['title'] ?? '')), briefing: trim((string) ($data['briefing'] ?? '')), model: (string) ($data['model'] ?? 'mistral'), collections: $collections, contextLimit: (int) ($data['context_limit'] ?? 5), authorProfileId: !empty($data['author_profile_id']) ? (int) $data['author_profile_id'] : null, contractId: !empty($data['contract_id']) ? (int) $data['contract_id'] : null, structureId: !empty($data['structure_id']) ? (int) $data['structure_id'] : null, action: (string) ($data['action'] ?? 'save'), ); } /** * Validate the command data. * * @return array List of validation errors (empty if valid) */ public function validate(): array { $errors = []; if ($this->title === '') { $errors[] = 'Titel ist erforderlich.'; } if ($this->briefing === '') { $errors[] = 'Briefing ist erforderlich.'; } if ($this->contextLimit < 1 || $this->contextLimit > 20) { $errors[] = 'Context-Limit muss zwischen 1 und 20 liegen.'; } if (empty($this->collections)) { $errors[] = 'Mindestens eine Collection ist erforderlich.'; } return $errors; } public function isValid(): bool { return $this->validate() === []; } public function shouldGenerate(): bool { return $this->action === 'generate'; } }