<?php

declare(strict_types=1);

namespace App\Scolarite\Infrastructure\Api\Resource;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Put;
use App\Scolarite\Infrastructure\Api\Processor\CancelOccurrenceProcessor;
use App\Scolarite\Infrastructure\Api\Processor\ModifyOccurrenceProcessor;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * API Resource pour les modifications ponctuelles d'occurrences de cours récurrents.
 *
 * @see Story 4.2 - Récurrences Hebdomadaires (AC3, AC5)
 */
#[ApiResource(
    shortName: 'ScheduleOccurrence',
    operations: [
        new Put(
            uriTemplate: '/schedule/slots/{id}/occurrence/{date}',
            read: false,
            processor: ModifyOccurrenceProcessor::class,
            name: 'modify_schedule_occurrence',
        ),
        new Delete(
            uriTemplate: '/schedule/slots/{id}/occurrence/{date}',
            read: false,
            processor: CancelOccurrenceProcessor::class,
            name: 'cancel_schedule_occurrence',
        ),
    ],
)]
final class ScheduleOccurrenceResource
{
    #[ApiProperty(identifier: true)]
    public ?string $id = null;

    /**
     * 'this_occurrence' (modifier uniquement cette date) ou 'all_future' (toutes les futures).
     */
    #[Assert\Choice(choices: ['this_occurrence', 'all_future'], message: 'Le scope doit être "this_occurrence" ou "all_future".')]
    public ?string $scope = 'this_occurrence';

    public ?string $classId = null;

    public ?string $subjectId = null;

    public ?string $teacherId = null;

    public ?int $dayOfWeek = null;

    #[Assert\Regex(pattern: '/^([01]\d|2[0-3]):[0-5]\d$/', message: "L'heure doit être au format HH:MM.")]
    public ?string $startTime = null;

    #[Assert\Regex(pattern: '/^([01]\d|2[0-3]):[0-5]\d$/', message: "L'heure doit être au format HH:MM.")]
    public ?string $endTime = null;

    public ?string $room = null;

    public ?string $reason = null;

    public ?string $type = null;

    public ?string $date = null;

    public ?string $slotId = null;
}
