<?php

declare(strict_types=1);

namespace App\Scolarite\Application\Query\GetStudentHomework;

use App\Scolarite\Domain\Model\Homework\Homework;

final readonly class StudentHomeworkDto
{
    public function __construct(
        public string $id,
        public string $subjectId,
        public string $subjectName,
        public ?string $subjectColor,
        public string $teacherId,
        public string $teacherName,
        public string $title,
        public ?string $description,
        public string $dueDate,
        public string $createdAt,
        public bool $hasAttachments,
        public ?string $submissionStatus = null,
    ) {
    }

    public static function fromDomain(
        Homework $homework,
        string $subjectName,
        ?string $subjectColor,
        string $teacherName,
        bool $hasAttachments,
        ?string $submissionStatus = null,
    ): self {
        return new self(
            id: (string) $homework->id,
            subjectId: (string) $homework->subjectId,
            subjectName: $subjectName,
            subjectColor: $subjectColor,
            teacherId: (string) $homework->teacherId,
            teacherName: $teacherName,
            title: $homework->title,
            description: $homework->description,
            dueDate: $homework->dueDate->format('Y-m-d'),
            createdAt: $homework->createdAt->format('Y-m-d\TH:i:sP'),
            hasAttachments: $hasAttachments,
            submissionStatus: $submissionStatus,
        );
    }
}
