<?php

declare(strict_types=1);

namespace App\Administration\Application\Query\GetPeriods;

use App\Administration\Domain\Model\AcademicYear\AcademicPeriod;
use DateTimeImmutable;

/**
 * DTO pour représenter une période scolaire dans les réponses de query.
 */
final readonly class PeriodDto
{
    public function __construct(
        public int $sequence,
        public string $label,
        public string $startDate,
        public string $endDate,
        public bool $isCurrent,
        public int $daysRemaining,
        public bool $isPast,
    ) {
    }

    public static function fromDomain(AcademicPeriod $period, DateTimeImmutable $now): self
    {
        return new self(
            sequence: $period->sequence,
            label: $period->label,
            startDate: $period->startDate->format('Y-m-d'),
            endDate: $period->endDate->format('Y-m-d'),
            isCurrent: $period->containsDate($now),
            daysRemaining: $period->daysRemaining($now),
            isPast: $period->isPast($now),
        );
    }
}
