<?php

declare(strict_types=1);

namespace App\ApiResources\Cotisation;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use App\ApiResources\ApiResourcesInterface;
use App\Enum\Cotisation\AlertStateEnum;
use App\State\Provider\Cotisation\CotisationProvider;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Classe resource qui contient les informations des cotisations de la 5.9.
 *
 * Security :
 *
 *   * @see App\Security\Voter\CotisationVoter
 */
#[ApiResource(operations: [
    new Get(
        uriTemplate: '/cotisations/{organizationId}',
        security: 'is_granted("ROLE_COTISATION", object) and object.getOrganizationId() == user.getOrganization().getId()',
        provider: CotisationProvider::class
    ),
])]
class Cotisation implements ApiResourcesInterface
{
    #[ApiProperty(identifier: true)]
    private int $organizationId;

    #[Assert\Type(type: AlertStateEnum::class)]
    private ?AlertStateEnum $alertState = null;

    private ?int $cotisationYear = null;

    public function getOrganizationId(): ?int
    {
        return $this->organizationId;
    }

    public function setOrganizationId(?int $organizationId): self
    {
        $this->organizationId = $organizationId;

        return $this;
    }

    public function getAlertState(): ?AlertStateEnum
    {
        return $this->alertState;
    }

    public function setAlertState(?AlertStateEnum $alertState): self
    {
        $this->alertState = $alertState;

        return $this;
    }

    public function getCotisationYear(): ?int
    {
        return $this->cotisationYear;
    }

    public function setCotisationYear(?int $cotisationYear): self
    {
        $this->cotisationYear = $cotisationYear;

        return $this;
    }
}
