<?php

namespace App\Modules\HR\Employees\DTOs;

final readonly class EmergencyContactWriteData
{
    public function __construct(
        public string $fullName,
        public string $relationship,
        public string $phone,
        public ?string $phoneAlt,
        public ?string $email,
        public ?string $address,
        public bool $isPrimary,
        public ?string $notes,
    ) {}

    /** @param  array<string, mixed>  $data */
    public static function fromValidated(array $data): self
    {
        return new self(
            fullName: (string) $data['full_name'],
            relationship: (string) $data['relationship'],
            phone: (string) $data['phone'],
            phoneAlt: isset($data['phone_alt']) ? (string) $data['phone_alt'] : null,
            email: isset($data['email']) ? (string) $data['email'] : null,
            address: isset($data['address']) ? (string) $data['address'] : null,
            isPrimary: (bool) ($data['is_primary'] ?? false),
            notes: isset($data['notes']) ? (string) $data['notes'] : null,
        );
    }

    /** @return array<string, mixed> */
    public function toArray(): array
    {
        return [
            'full_name' => $this->fullName,
            'relationship' => $this->relationship,
            'phone' => $this->phone,
            'phone_alt' => $this->phoneAlt,
            'email' => $this->email,
            'address' => $this->address,
            'is_primary' => $this->isPrimary,
            'notes' => $this->notes,
        ];
    }
}
