<?php

declare(strict_types=1);

namespace App\Module\ProjectManagement\Domain\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Module\ProjectManagement\Infrastructure\Doctrine\DoctrineTaskTagRepository;
use App\Shared\Domain\Contract\TaskTagInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(
    operations: [
        new GetCollection(paginationEnabled: false, security: "is_granted('project-management.projects.view') or is_granted('project-management.tasks.view')"),
        new Get(security: "is_granted('project-management.projects.view') or is_granted('project-management.tasks.view')"),
        new Post(security: "is_granted('project-management.projects.manage') or is_granted('project-management.tasks.manage')"),
        new Patch(security: "is_granted('project-management.projects.manage') or is_granted('project-management.tasks.manage')"),
        new Delete(security: "is_granted('project-management.projects.manage') or is_granted('project-management.tasks.manage')"),
    ],
    normalizationContext: ['groups' => ['task_tag:read']],
    denormalizationContext: ['groups' => ['task_tag:write']],
    order: ['label' => 'ASC'],
)]
#[ORM\Entity(repositoryClass: DoctrineTaskTagRepository::class)]
#[ORM\Table(name: 'task_type')]
class TaskTag implements TaskTagInterface
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    #[Groups(['task_tag:read', 'task:read', 'time_entry:read'])]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    #[Groups(['task_tag:read', 'task_tag:write', 'task:read', 'time_entry:read'])]
    private ?string $label = null;

    #[ORM\Column(length: 7)]
    #[Groups(['task_tag:read', 'task_tag:write', 'task:read', 'time_entry:read'])]
    private ?string $color = '#222783';

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

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

    public function setLabel(string $label): static
    {
        $this->label = $label;

        return $this;
    }

    public function getColor(): ?string
    {
        return $this->color;
    }

    public function setColor(string $color): static
    {
        $this->color = $color;

        return $this;
    }
}
