<?php

namespace App\Modules\HR\Employees\DTOs;

final readonly class EmployeeSkillWriteData
{
    public function __construct(
        public string $name,
        public string $level,
        public ?int $yearsExperience,
        public bool $isCertified,
        public ?string $notes,
    ) {}

    /** @param  array<string, mixed>  $data */
    public static function fromValidated(array $data): self
    {
        return new self(
            name: (string) $data['name'],
            level: (string) $data['level'],
            yearsExperience: isset($data['years_experience']) ? (int) $data['years_experience'] : null,
            isCertified: (bool) ($data['is_certified'] ?? false),
            notes: isset($data['notes']) ? (string) $data['notes'] : null,
        );
    }

    /** @return array<string, mixed> */
    public function toArray(): array
    {
        return [
            'name' => $this->name,
            'level' => $this->level,
            'years_experience' => $this->yearsExperience,
            'is_certified' => $this->isCertified,
            'notes' => $this->notes,
        ];
    }
}
