value; public function toData(): CustomerJobData { $this->validate(); return new CustomerJobData( name: $this->name, customerId: (int) $this->customer_id, serviceUnitIds: [(int) $this->service_unit_id], responsibleUserId: (int) $this->responsible_user_id, kind: JobKind::OneOff->value, status: $this->status, priority: Priority::Normal->value, description: trim($this->description) === '' ? null : $this->description, ); } /** * Empties the form for the next job; responsible person and status stay. */ public function clearForNextJob(): void { $this->reset('customer_id', 'name', 'description', 'service_unit_id'); $this->resetErrorBag(); } public function showDomainError(DomainException $exception): void { [$field, $key] = match (true) { $exception instanceof InvalidJobName => ['name', 'jobs.errors.invalid_name'], $exception instanceof ServiceUnitRequired => ['service_unit_id', 'jobs.errors.service_units_required'], $exception instanceof InvalidJobReference => [match ($exception->field) { 'customer' => 'customer_id', 'service_units' => 'service_unit_id', default => 'responsible_user_id', }, 'jobs.errors.invalid_reference'], default => throw $exception, }; $this->addError($field, __($key)); } /** * @return array> */ protected function rules(): array { return [ 'customer_id' => ['required', 'integer'], 'name' => ['required', 'string', 'max:255'], 'description' => ['nullable', 'string', 'max:2000'], 'service_unit_id' => ['required', 'integer'], 'responsible_user_id' => ['required', 'integer'], 'status' => ['required', Rule::in([JobStatus::Tentative->value, JobStatus::Prospect->value])], ]; } /** * @return array */ protected function messages(): array { return [ 'customer_id.required' => __('jobs.errors.customer_required'), 'name.required' => __('jobs.errors.name_required'), 'name.max' => __('jobs.errors.invalid_name'), 'description.max' => __('jobs.errors.too_long', ['max' => 2000]), 'service_unit_id.required' => __('jobs.quick.service_unit_required'), 'responsible_user_id.required' => __('jobs.errors.responsible_required'), 'status.in' => __('jobs.errors.status_not_allowed'), ]; } }