<?php

namespace App\Modules\HR\Contracts\DTOs;

final readonly class ContractWriteData
{
    public function __construct(
        public int $employeeId,
        public string $contractType,
        public string $startDate,
        public ?string $endDate,
        public ?string $notes,
        public bool $isActive,
        public ?int $templateId,
    ) {}

    /**
     * @param  array<string, mixed>  $data
     */
    public static function fromValidated(array $data): self
    {
        return new self(
            employeeId: (int) $data['employee_id'],
            contractType: (string) $data['contract_type'],
            startDate: (string) $data['start_date'],
            endDate: isset($data['end_date']) ? (string) $data['end_date'] : null,
            notes: isset($data['notes']) ? (string) $data['notes'] : null,
            isActive: (bool) ($data['is_active'] ?? true),
            templateId: isset($data['template_id']) ? (int) $data['template_id'] : null,
        );
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'employee_id' => $this->employeeId,
            'contract_type' => $this->contractType,
            'start_date' => $this->startDate,
            'end_date' => $this->endDate,
            'notes' => $this->notes,
            'is_active' => $this->isActive,
            'template_id' => $this->templateId,
        ];
    }
}
