resolveContractNature($employee->getContractNature()), contractStartDate: $this->parseOptionalYmd($employee->getContractStartDate(), 'contractStartDate'), contractEndDate: $this->parseOptionalYmd($employee->getContractEndDate(), 'contractEndDate'), contractPaidLeaveSettled: $employee->getContractPaidLeaveSettled(), contractComment: $employee->getContractComment(), isDriver: $employee->getIsDriverInput(), workDaysHours: $employee->getWorkDaysHoursInput(), interimAgencyId: $employee->getInterimAgencyId(), ); } private function resolveContractNature(?string $raw): ?ContractNature { if (null === $raw || '' === trim($raw)) { return null; } return ContractNature::tryFrom(trim($raw)) ?? throw new UnprocessableEntityHttpException('contractNature must be one of CDI, CDD, INTERIM.'); } private function parseOptionalYmd(?string $raw, string $field): ?DateTimeImmutable { if (null === $raw || '' === trim($raw)) { return null; } $value = trim($raw); $date = DateTimeImmutable::createFromFormat('Y-m-d', $value); if (!$date || $date->format('Y-m-d') !== $value) { throw new UnprocessableEntityHttpException(sprintf('%s must use Y-m-d format.', $field)); } return $date; } }