<?php

declare(strict_types=1);

namespace App\Scolarite\Application\Query\GetStudentSchedule;

use App\Scolarite\Domain\Model\Schedule\ResolvedScheduleSlot;

final readonly class StudentScheduleSlotDto
{
    public function __construct(
        public string $slotId,
        public string $date,
        public int $dayOfWeek,
        public string $startTime,
        public string $endTime,
        public string $subjectId,
        public string $subjectName,
        public ?string $subjectColor,
        public string $teacherId,
        public string $teacherName,
        public ?string $room,
        public bool $isModified,
        public ?string $exceptionId,
    ) {
    }

    public static function fromResolved(
        ResolvedScheduleSlot $slot,
        string $subjectName,
        ?string $subjectColor,
        string $teacherName,
    ): self {
        return new self(
            slotId: (string) $slot->slotId,
            date: $slot->date->format('Y-m-d'),
            dayOfWeek: $slot->dayOfWeek->value,
            startTime: $slot->timeSlot->startTime,
            endTime: $slot->timeSlot->endTime,
            subjectId: (string) $slot->subjectId,
            subjectName: $subjectName,
            subjectColor: $subjectColor,
            teacherId: (string) $slot->teacherId,
            teacherName: $teacherName,
            room: $slot->room,
            isModified: $slot->isModified,
            exceptionId: $slot->exceptionId !== null ? (string) $slot->exceptionId : null,
        );
    }
}
