<?php

namespace App\ApiResource;

use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Doctrine\Orm\State\Options;
use App\Entity\Event;
use App\Filter\CustomJsonFilter;
use App\Filter\CustomJsonOrderFilter;
use App\State\EntityClassDtoStateProcessor;
use App\State\EntityToDtoStateProvider;

#[ApiResource(
    shortName: 'Event',
    operations: [
        new Get(
            security: 'is_granted("ROLE_USER")'
        ),
        new GetCollection(
            security: 'is_granted("ROLE_USER")'
        ),
    ],
    security: 'is_granted("ROLE_USER")',
    provider: EntityToDtoStateProvider::class,
    processor: EntityClassDtoStateProcessor::class,
    stateOptions: new Options(entityClass: Event::class),
)]
#[ApiFilter(SearchFilter::class, properties: [
    'name' => 'ipartial',
])]
#[ApiFilter(CustomJsonFilter::class)]
#[ApiFilter(CustomJsonOrderFilter::class)]
class EventApi
{
    #[ApiProperty(readable: false, writable: false, identifier: true)]
    public ?int $id = null;

    #[ApiProperty(writable: false)]
    public ?int $dbId = null;

    public string $name;

    public string $identifier;

    public int $sequence;

    public bool $mandatory;

    #[ApiProperty(writable: false)]
    public ?\DateTimeImmutable $createdAt = null;
}