<?php

declare(strict_types=1);

namespace App\Entity\Public;

use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Filter\ApiPlatform\Utils\FindInSetFilter;
use App\Repository\Public\FederationStructureRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * Structure telle qu'elle est représentée sur l'iframe de recherche des structures d'une fédération.
 *
 * Fichier source de la view : ./sql/schema-extensions/002-view_federation_structures.sql
 */
#[ApiResource(
    operations: [
        new Get(
            uriTemplate: '/public/federation_structures/{id}',
            requirements: ['id' => '\\d+'],
            normalizationContext: ['groups' => ['federation_structure_item_get']]
        ),
        new GetCollection(
            uriTemplate: '/public/federation_structures',
            normalizationContext: ['groups' => ['federation_structure_collection_get']]
        ),
    ],
    paginationEnabled: false
)]
#[ORM\Entity(repositoryClass: FederationStructureRepository::class, readOnly: true)]
#[ORM\Table(name: 'view_federation_structures')]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['name' => 'partial', 'city' => 'exact'])]
#[ApiFilter(filterClass: NumericFilter::class, properties: ['id', 'parentId'])]
#[ApiFilter(filterClass: FindInSetFilter::class, properties: ['parents'])]
#[ApiFilter(filterClass: BooleanFilter::class, properties: ['isFederation', 'portailVisibility'])]
class FederationStructure
{
    #[ORM\Id]
    #[ORM\Column]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private int $id;

    #[ORM\Column]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private string $name;

    #[ORM\Column(type: 'integer', nullable: true)]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private ?int $logoId;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get'])]
    private ?string $description;

    #[ORM\Column(type: 'integer', nullable: true)]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private ?int $imageId;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private ?string $type;

    #[ORM\Column(options: ['default' => false])]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private bool $isFederation = false;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private ?string $website;

    /** @var mixed[] */
    #[ORM\Column(type: 'json')]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private array $addresses = [];

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get'])]
    private ?string $phone = null;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get'])]
    private ?string $mobilePhone;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get'])]
    private ?string $email;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get'])]
    private ?string $facebook;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get'])]
    private ?string $twitter;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get'])]
    private ?string $instagram;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get'])]
    private ?string $youtube;

    /** @var mixed[]|null */
    #[ORM\Column(type: 'json', nullable: true)]
    #[Groups(['federation_structure_item_get'])]
    private ?array $articles;

    /** @var list<string>|null */
    #[ORM\Column(type: 'simple_array', nullable: true)]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private ?array $practices;

    #[ORM\Column(type: 'integer', nullable: true)]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private ?int $parentId;

    #[ORM\Column(nullable: true)]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private ?string $parentName;

    /** @var list<string> */
    #[ORM\Column(type: 'simple_array')]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private array $parents;

    #[ORM\Column(options: ['default' => false])]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private bool $portailVisibility = false;

    /** @var mixed[] */
    #[ORM\Column(type: 'json')]
    #[Groups(['federation_structure_item_get', 'federation_structure_collection_get'])]
    private array $sections;

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

    public function setId(int $id): FederationStructure
    {
        $this->id = $id;

        return $this;
    }

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

    public function setName(string $name): FederationStructure
    {
        $this->name = $name;

        return $this;
    }

    public function getLogoId(): ?int
    {
        return $this->logoId;
    }

    public function setLogoId(?int $logoId): FederationStructure
    {
        $this->logoId = $logoId;

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(?string $description): FederationStructure
    {
        $this->description = $description;

        return $this;
    }

    public function getImageId(): ?int
    {
        return $this->imageId;
    }

    public function setImageId(?int $imageId): FederationStructure
    {
        $this->imageId = $imageId;

        return $this;
    }

    public function getType(): ?string
    {
        return $this->type;
    }

    public function setType(?string $type): FederationStructure
    {
        $this->type = $type;

        return $this;
    }

    public function getIsFederation(): bool
    {
        return $this->isFederation;
    }

    public function setIsFederation(bool $isFederation): self
    {
        $this->isFederation = $isFederation;

        return $this;
    }

    public function getWebsite(): ?string
    {
        return $this->website;
    }

    public function setWebsite(?string $website): FederationStructure
    {
        $this->website = $website;

        return $this;
    }

    /**
     * @return mixed[]
     */
    public function getAddresses(): array
    {
        return $this->addresses;
    }

    /**
     * @param mixed[] $addresses
     */
    public function setAddresses(array $addresses): FederationStructure
    {
        $this->addresses = $addresses;

        return $this;
    }

    public function getPhone(): ?string
    {
        return $this->phone;
    }

    public function setPhone(?string $phone): FederationStructure
    {
        $this->phone = $phone;

        return $this;
    }

    public function getMobilePhone(): ?string
    {
        return $this->mobilePhone;
    }

    public function setMobilePhone(?string $mobilePhone): FederationStructure
    {
        $this->mobilePhone = $mobilePhone;

        return $this;
    }

    public function getEmail(): ?string
    {
        return $this->email;
    }

    public function setEmail(?string $email): self
    {
        $this->email = $email;

        return $this;
    }

    public function getFacebook(): ?string
    {
        return $this->facebook;
    }

    public function setFacebook(?string $facebook): self
    {
        $this->facebook = $facebook;

        return $this;
    }

    public function getTwitter(): ?string
    {
        return $this->twitter;
    }

    public function setTwitter(?string $twitter): self
    {
        $this->twitter = $twitter;

        return $this;
    }

    public function getInstagram(): ?string
    {
        return $this->instagram;
    }

    public function setInstagram(?string $instagram): self
    {
        $this->instagram = $instagram;

        return $this;
    }

    public function getYoutube(): ?string
    {
        return $this->youtube;
    }

    public function setYoutube(?string $youtube): FederationStructure
    {
        $this->youtube = $youtube;

        return $this;
    }

    /**
     * @return mixed[]|null
     */
    public function getArticles(): ?array
    {
        return $this->articles;
    }

    /**
     * @param mixed[]|null $articles
     */
    public function setArticles(?array $articles): FederationStructure
    {
        $this->articles = $articles;

        return $this;
    }

    /**
     * @return list<string>|null
     */
    public function getPractices(): ?array
    {
        return $this->practices;
    }

    /**
     * @param list<string>|null $practices
     */
    public function setPractices(?array $practices): FederationStructure
    {
        $this->practices = $practices;

        return $this;
    }

    public function getParentId(): ?int
    {
        return $this->parentId;
    }

    public function setParentId(?int $parentId): FederationStructure
    {
        $this->parentId = $parentId;

        return $this;
    }

    public function getParentName(): ?string
    {
        return $this->parentName;
    }

    public function setParentName(?string $parentName): FederationStructure
    {
        $this->parentName = $parentName;

        return $this;
    }

    /**
     * @return list<string>
     */
    public function getParents(): array
    {
        return $this->parents;
    }

    /**
     * @param list<string> $parents
     */
    public function setParents(array $parents): FederationStructure
    {
        $this->parents = $parents;

        return $this;
    }

    public function getPortailVisibility(): bool
    {
        return $this->portailVisibility;
    }

    public function setPortailVisibility(bool $portailVisibility): FederationStructure
    {
        $this->portailVisibility = $portailVisibility;

        return $this;
    }

    /**
     * @return mixed[]
     */
    public function getSections(): array
    {
        return $this->sections;
    }

    /**
     * @param mixed[] $sections
     */
    public function setSections(array $sections): FederationStructure
    {
        $this->sections = $sections;

        return $this;
    }
}
