<?php

namespace App\Modules\HR\Recruitment\DTOs;

final readonly class InterviewWriteData
{
    public function __construct(
        public int $applicationId,
        public string $scheduledAt,
        public string $mode,
        public ?string $location,
        public ?int $interviewerUserId,
        public ?string $notes,
        public ?string $status = null,
    ) {}

    /** @param  array<string, mixed>  $data */
    public static function fromValidated(array $data): self
    {
        return new self(
            applicationId: (int) $data['application_id'],
            scheduledAt: (string) $data['scheduled_at'],
            mode: (string) $data['mode'],
            location: isset($data['location']) ? (string) $data['location'] : null,
            interviewerUserId: isset($data['interviewer_user_id']) ? (int) $data['interviewer_user_id'] : null,
            notes: isset($data['notes']) ? (string) $data['notes'] : null,
            status: isset($data['status']) ? (string) $data['status'] : null,
        );
    }

    /** @return array<string, mixed> */
    public function toArray(): array
    {
        $payload = [
            'application_id' => $this->applicationId,
            'scheduled_at' => $this->scheduledAt,
            'mode' => $this->mode,
            'location' => $this->location,
            'interviewer_user_id' => $this->interviewerUserId,
            'notes' => $this->notes,
        ];
        if ($this->status !== null) {
            $payload['status'] = $this->status;
        }

        return $payload;
    }
}
