<?php

declare(strict_types=1);

namespace App\Scolarite\Infrastructure\Api\Resource;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use App\Scolarite\Infrastructure\Api\Processor\CreateHomeworkWithExceptionProcessor;
use App\Scolarite\Infrastructure\Api\Provider\HomeworkExceptionsReportProvider;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
    shortName: 'HomeworkException',
    operations: [
        new Post(
            uriTemplate: '/homework/with-exception',
            processor: CreateHomeworkWithExceptionProcessor::class,
            validationContext: ['groups' => ['Default', 'create']],
            name: 'create_homework_with_exception',
        ),
        new GetCollection(
            uriTemplate: '/admin/homework-exceptions',
            provider: HomeworkExceptionsReportProvider::class,
            name: 'get_homework_exceptions_report',
        ),
    ],
)]
final class HomeworkExceptionResource
{
    #[ApiProperty(identifier: true)]
    public ?string $id = null;

    // --- Input fields for POST (create with exception) ---

    #[Assert\NotBlank(message: 'La classe est requise.', groups: ['create'])]
    #[Assert\Uuid(message: 'L\'identifiant de la classe doit être un UUID valide.', groups: ['create'])]
    public ?string $classId = null;

    #[Assert\NotBlank(message: 'La matière est requise.', groups: ['create'])]
    #[Assert\Uuid(message: 'L\'identifiant de la matière doit être un UUID valide.', groups: ['create'])]
    public ?string $subjectId = null;

    #[Assert\NotBlank(message: 'Le titre est requis.', groups: ['create'])]
    #[Assert\Length(max: 255, maxMessage: 'Le titre ne peut pas dépasser 255 caractères.')]
    public ?string $title = null;

    public ?string $description = null;

    #[Assert\NotBlank(message: 'La date d\'échéance est requise.', groups: ['create'])]
    public ?string $dueDate = null;

    #[Assert\NotBlank(message: 'La justification est requise.', groups: ['create'])]
    #[Assert\Length(min: 20, minMessage: 'La justification doit contenir au moins 20 caractères.', groups: ['create'])]
    public ?string $justification = null;

    /** @var string[]|null */
    public ?array $ruleTypes = null;

    // --- Output fields ---

    public ?string $homeworkId = null;
    public ?string $homeworkTitle = null;
    public ?string $ruleType = null;
    public ?string $teacherId = null;
    public ?string $teacherName = null;
    public ?string $createdAt = null;
    public ?bool $hasRuleException = null;
}
