<?php

declare(strict_types=1);

namespace App\Administration\Infrastructure\Api\Resource;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use App\Administration\Infrastructure\Api\Processor\ConfigurePeriodsProcessor;
use App\Administration\Infrastructure\Api\Processor\UpdatePeriodProcessor;
use App\Administration\Infrastructure\Api\Provider\PeriodsProvider;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * API Resource pour la gestion des périodes scolaires.
 *
 * @see FR75 - Structurer l'année pour bulletins et moyennes
 */
#[ApiResource(
    shortName: 'Period',
    operations: [
        new Get(
            uriTemplate: '/academic-years/{academicYearId}/periods',
            provider: PeriodsProvider::class,
            name: 'get_periods',
        ),
        new Put(
            uriTemplate: '/academic-years/{academicYearId}/periods',
            read: false,
            processor: ConfigurePeriodsProcessor::class,
            name: 'configure_periods',
        ),
        new Patch(
            uriTemplate: '/academic-years/{academicYearId}/periods/{sequence}',
            read: false,
            processor: UpdatePeriodProcessor::class,
            name: 'update_period',
        ),
    ],
)]
final class PeriodResource
{
    #[ApiProperty(identifier: true)]
    public ?string $academicYearId = null;

    public ?int $sequence = null;

    #[Assert\Choice(choices: ['trimester', 'semester'], message: 'Le type de période doit être "trimester" ou "semester".')]
    public ?string $periodType = null;

    public ?int $startYear = null;

    #[Assert\Date(message: 'La date de début doit être une date valide (YYYY-MM-DD).')]
    public ?string $startDate = null;

    #[Assert\Date(message: 'La date de fin doit être une date valide (YYYY-MM-DD).')]
    public ?string $endDate = null;

    public ?string $label = null;

    public ?bool $isCurrent = null;

    public ?int $daysRemaining = null;

    public ?bool $isPast = null;

    public ?bool $confirmImpact = null;

    /** @var PeriodItem[]|null */
    public ?array $periods = null;

    public ?string $type = null;

    public ?PeriodItem $currentPeriod = null;
}
