<?php

namespace App\Modules\HR\Employees\DTOs;

final readonly class EmploymentHistoryWriteData
{
    /** @param array<string, mixed>|null $meta */
    public function __construct(
        public string $type,
        public string $effectiveDate,
        public ?string $previousValue,
        public ?string $newValue,
        public ?string $reason,
        public ?string $notes,
        public ?array $meta,
    ) {}

    /** @param array<string,mixed> $data */
    public static function fromValidated(array $data): self
    {
        return new self(
            (string) $data['type'], (string) $data['effective_date'],
            $data['previous_value'] ?? null, $data['new_value'] ?? null,
            $data['reason'] ?? null, $data['notes'] ?? null, $data['meta'] ?? null,
        );
    }

    /** @return array<string,mixed> */
    public function toArray(): array
    {
        return [
            'type' => $this->type, 'effective_date' => $this->effectiveDate,
            'previous_value' => $this->previousValue, 'new_value' => $this->newValue,
            'reason' => $this->reason, 'notes' => $this->notes, 'meta' => $this->meta,
        ];
    }
}
