<?php
declare (strict_types=1);

namespace App\ApiResources\Profile;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Put;
use App\ApiResources\ApiResourcesInterface;
use App\State\Processor\Access\AdminAccessProcessor;
use App\State\Provider\Access\AccessProfileProvider;
use App\State\Provider\Access\AdminAccessProvider;
use JetBrains\PhpStorm\Pure;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

/**
 * Classe resource qui contient les champs disponibles lors d'un appel à my_profile.
 */
#[ApiResource(
    operations: [
        new Get(
            uriTemplate: '/my_profile/{id}',
            defaults: ['id' => 0],
            normalizationContext: ['groups' => ['access_profile_read']],
            provider: AccessProfileProvider::class
        )
    ]
)]
class AccessProfile implements ApiResourcesInterface
{
    #[ApiProperty(identifier: true)]
    #[Groups('access_profile_read')]
    public ?int $id = null;

    #[Groups('access_profile_read')]
    private bool $isAdminAccess = false;

    #[Groups('access_profile_read')]
    private bool $isSuperAdminAccess = false;

    #[Groups('access_profile_read')]
    private ?string $name = null;

    #[Groups('access_profile_read')]
    private ?string $givenName = null;

    #[Groups('access_profile_read')]
    private ?string $gender = null;

    #[Groups('access_profile_read')]
    private ?int $avatarId = null;

    /** @var list<string> $roles */
    #[Groups('access_profile_read')]
    private ?array $roles = [];

    #[Groups('access_profile_read')]
    private ?int $activityYear = null;

    /** @var bool[] $historical */
    #[Groups('access_profile_read')]
    private ?array $historical = [];

    #[Groups('access_profile_read')]
    private bool $isGuardian = false;

    #[Groups('access_profile_read')]
    private bool $isPayor = false;

    #[Groups('access_profile_read')]
    private ?OrganizationProfile $organization = null;

    #[Groups('access_profile_read')]
    private Collection $multiAccesses;

    #[Groups('access_profile_read')]
    private Collection $familyAccesses;

    #[Groups('access_profile_read')]
    private ?AccessProfile $originalAccess = null;

    #[Pure]
    public function __construct()
    {
        $this->multiAccesses = new ArrayCollection();
        $this->familyAccesses = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function setId(?int $id): self
    {
        $this->id = $id;
        return $this;
    }

    public function getIsAdminAccess(): bool
    {
        return $this->isAdminAccess;
    }

    public function setIsAdminAccess(bool $isAdminAccess): self
    {
        $this->isAdminAccess = $isAdminAccess;
        return $this;
    }

    public function getIsSuperAdminAccess(): bool
    {
        return $this->isSuperAdminAccess;
    }

    public function setIsSuperAdminAccess(bool $isSuperAdminAccess): self
    {
        $this->isSuperAdminAccess = $isSuperAdminAccess;
        return $this;
    }

    public function getOrganization(): ?OrganizationProfile
    {
        return $this->organization;
    }

    public function setOrganization(?OrganizationProfile $organization): self
    {
        $this->organization = $organization;
        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(?string $name): self
    {
        $this->name = $name;
        return $this;
    }

    public function getGivenName(): ?string
    {
        return $this->givenName;
    }

    public function setGivenName(?string $givenName): self
    {
        $this->givenName = $givenName;
        return $this;
    }

    public function getGender(): ?string
    {
        return $this->gender;
    }

    public function setGender(?string $gender): self
    {
        $this->gender = $gender;
        return $this;
    }

    public function getAvatarId(): ?int
    {
        return $this->avatarId;
    }

    public function setAvatarId(?int $avatarId): self
    {
        $this->avatarId = $avatarId;
        return $this;
    }

    /**
     * @return list<string>
     */
    public function getRoles(): array
    {
        $roles = $this->roles;
        return array_unique($roles);
    }

    /**
     * @param list<string> $roles
     * @return $this
     */
    public function setRoles(array $roles): self
    {
        $this->roles = $roles;
        return $this;
    }

    public function getIsGuardian(): bool
    {
        return $this->isGuardian;
    }

    public function setIsGuardian(bool $isGuardian): self
    {
        $this->isGuardian = $isGuardian;
        return $this;
    }

    public function getIsPayor(): bool
    {
        return $this->isPayor;
    }

    public function setIsPayor(bool $isPayor): self
    {
        $this->isPayor = $isPayor;
        return $this;
    }

    public function getMultiAccesses(): Collection
    {
        return $this->multiAccesses;
    }

    public function addMultiAccess(OrganizationProfile $organizationProfile): self
    {
        if (!$this->multiAccesses->contains($organizationProfile)) {
            $this->multiAccesses[] = $organizationProfile;
        }
        return $this;
    }

    public function removeMultiAccess(OrganizationProfile $organizationProfile): self
    {
        $this->multiAccesses->removeElement($organizationProfile);
        return $this;
    }

    public function getFamilyAccesses(): Collection
    {
        return $this->familyAccesses;
    }

    public function addFamilyAccess(AccessProfile $accessProfile): self
    {
        if (!$this->familyAccesses->contains($accessProfile)) {
            $this->familyAccesses[] = $accessProfile;
        }
        return $this;
    }

    public function removeFamilyAccess(AccessProfile $accessProfile): self
    {
        $this->familyAccesses->removeElement($accessProfile);
        return $this;
    }

    public function getOriginalAccess(): ?AccessProfile
    {
        return $this->originalAccess;
    }

    public function setOriginalAccess(?AccessProfile $originalAccess): self
    {
        $this->originalAccess = $originalAccess;
        return $this;
    }

    public function getActivityYear(): ?int
    {
        return $this->activityYear;
    }

    public function setActivityYear(?int $activityYear): self
    {
        $this->activityYear = $activityYear;
        return $this;
    }

    /**
     * @return bool[]
     */
    public function getHistorical(): array
    {
        return $this->historical;
    }

    /**
     * @param bool[] $historical
     * @return $this
     */
    public function setHistorical(array $historical): self
    {
        $this->historical = $historical;
        return $this;
    }
}
