<?php

declare (strict_types=1);

namespace App\Entity\Access;

use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\Access\PersonalizedListRepository;
use Doctrine\ORM\Mapping as ORM;
use JetBrains\PhpStorm\Pure;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * Liste personnalisées
 */
#[ApiResource(
    operations: [
        new Get(
            security: 'object.getAccess().getId() == user.getId()'
        ),
        new GetCollection(
            normalizationContext: ['groups' => ['lists:output']]
        )
    ],
    paginationEnabled: false
)]
#[ORM\Entity(repositoryClass: PersonalizedListRepository::class)]
class PersonalizedList
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    #[Groups(['lists:output'])]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'personalizedLists')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Access $access = null;

    #[ORM\Column(length: 200, nullable: true)]
    #[Groups(['lists:output'])]
    private ?string $label = null;

    /** @var mixed[]|null  */
    #[ORM\Column(length: 4294967295, nullable: true)]
    private ?array $filters = null;

    #[ORM\Column(length: 150)]
    #[Groups(['lists:output'])]
    private string $entity;

    /** @var mixed[]  */
    #[ORM\Column(length: 4294967295, nullable: true)]
    private array $columns;

    #[ORM\Column(length: 150, nullable: true)]
    #[Groups(['lists:output'])]
    private string $menuKey;

    #[Pure]
    public function __construct()
    {
    }

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

    /**
     * @param mixed[] $filters
     * @return $this
     */
    public function setFilters(array $filters): self
    {
        $this->filters = $filters;
        return $this;
    }

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

    /**
     * @param mixed[] $columns
     * @return $this
     */
    public function setColumns(array $columns): self
    {
        $this->columns = $columns;
        return $this;
    }

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

    public function setAccess(?Access $access): self
    {
        $this->access = $access;
        return $this;
    }

    public function getAccess(): ?Access
    {
        return $this->access;
    }

    public function setMenuKey(string $menuKey): self
    {
        $this->menuKey = $menuKey;
        return $this;
    }

    public function getMenuKey(): ?string
    {
        return $this->menuKey;
    }

    public function setLabel(string $label): self
    {
        $this->label = $label;
        return $this;
    }

    public function getLabel(): ?string
    {
        return $this->label;
    }

    public function setEntity(string $entity): self
    {
        $this->entity = $entity;
        return $this;
    }

    public function getEntity(): ?string
    {
        return $this->entity;
    }
}
