<?php

namespace App\Modules\HR\EmploymentStatuses\DTOs;

final readonly class EmploymentStatusWriteData
{
    public function __construct(
        public string $name,
        public ?string $description,
        public string $color,
        public int $sortOrder,
        public bool $isActive,
    ) {}

    /**
     * @param  array<string, mixed>  $data
     */
    public static function fromValidated(array $data): self
    {
        return new self(
            name: (string) $data['name'],
            description: isset($data['description']) ? (string) $data['description'] : null,
            color: (string) $data['color'],
            sortOrder: isset($data['sort_order']) ? (int) $data['sort_order'] : 0,
            isActive: (bool) ($data['is_active'] ?? true),
        );
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'name' => $this->name,
            'description' => $this->description,
            'color' => $this->color,
            'sort_order' => $this->sortOrder,
            'is_active' => $this->isActive,
        ];
    }
}
