<?php

namespace App\Modules\HR\Recruitment\DTOs;

final readonly class CandidateWriteData
{
    public function __construct(
        public string $firstName,
        public string $lastName,
        public ?string $email,
        public ?string $phone,
        public ?string $nationality,
        public ?string $source,
        public ?string $notes,
    ) {}

    /**
     * @param  array<string, mixed>  $data
     */
    public static function fromValidated(array $data): self
    {
        return new self(
            firstName: (string) $data['first_name'],
            lastName: (string) $data['last_name'],
            email: isset($data['email']) ? (string) $data['email'] : null,
            phone: isset($data['phone']) ? (string) $data['phone'] : null,
            nationality: isset($data['nationality']) ? (string) $data['nationality'] : null,
            source: isset($data['source']) ? (string) $data['source'] : null,
            notes: isset($data['notes']) ? (string) $data['notes'] : null,
        );
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'first_name' => $this->firstName,
            'last_name' => $this->lastName,
            'email' => $this->email,
            'phone' => $this->phone,
            'nationality' => $this->nationality,
            'source' => $this->source,
            'notes' => $this->notes,
        ];
    }
}
