<?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\LinkCompetenciesToEvaluationProcessor;
use App\Scolarite\Infrastructure\Api\Provider\CompetencyEvaluationCollectionProvider;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
    shortName: 'CompetencyEvaluation',
    operations: [
        new GetCollection(
            uriTemplate: '/evaluations/{evaluationId}/competencies',
            uriVariables: ['evaluationId'],
            provider: CompetencyEvaluationCollectionProvider::class,
            name: 'get_evaluation_competencies',
        ),
        new Post(
            uriTemplate: '/evaluations/{evaluationId}/competencies',
            uriVariables: ['evaluationId'],
            read: false,
            processor: LinkCompetenciesToEvaluationProcessor::class,
            validationContext: ['groups' => ['Default', 'create']],
            name: 'link_competencies_to_evaluation',
        ),
    ],
)]
final class CompetencyEvaluationResource
{
    #[ApiProperty(identifier: true)]
    public ?string $id = null;

    public ?string $evaluationId = null;

    public ?string $competencyId = null;

    public ?string $competencyCode = null;

    public ?string $competencyName = null;

    /** @var array<string>|null */
    #[Assert\NotBlank(message: 'Les compétences sont requises.', groups: ['create'])]
    public ?array $competencyIds = null;
}
