<?php

declare(strict_types=1);

namespace App\Administration\Application\Query\GetSubjects;

use App\Administration\Domain\Model\Subject\Subject;
use DateTimeImmutable;

/**
 * DTO pour représenter une matière dans les réponses de query.
 */
final readonly class SubjectDto
{
    public function __construct(
        public string $id,
        public string $name,
        public string $code,
        public ?string $color,
        public ?string $description,
        public string $status,
        public DateTimeImmutable $createdAt,
        public DateTimeImmutable $updatedAt,
        public int $teacherCount = 0,
        public int $classCount = 0,
    ) {
    }

    public static function fromDomain(
        Subject $subject,
        int $teacherCount = 0,
        int $classCount = 0,
    ): self {
        return new self(
            id: (string) $subject->id,
            name: (string) $subject->name,
            code: (string) $subject->code,
            color: $subject->color !== null ? (string) $subject->color : null,
            description: $subject->description,
            status: $subject->status->value,
            createdAt: $subject->createdAt,
            updatedAt: $subject->updatedAt,
            teacherCount: $teacherCount,
            classCount: $classCount,
        );
    }
}
