<?php

namespace App\Tag\Entity;

use App\Tag\Repository\TagRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: TagRepository::class)]
#[ORM\Table(name: 'tags')]
#[ORM\UniqueConstraint(name: 'uq_tags_slug', columns: ['slug'])]
#[ORM\Index(columns: ['status'], name: 'idx_tags_status')]
class Tag
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 36, unique: true)]
    private string $uuid;

    #[ORM\Column(type: 'string', length: 255)]
    private string $name;

    #[ORM\Column(type: 'string', length: 255, unique: true)]
    private string $slug;

    #[ORM\Column(type: 'smallint')]
    private int $status = 1;

    public function __construct(string $name, string $slug)
    {
        $this->uuid = Uuid::v4()->toRfc4122();
        $this->name = $name;
        $this->slug = $slug;
    }

    public function getId(): ?int    { return $this->id; }
    public function getUuid(): string { return $this->uuid; }
    public function getName(): string { return $this->name; }
    public function getSlug(): string { return $this->slug; }
    public function getStatus(): int  { return $this->status; }

    public function setName(string $v): self  { $this->name = $v; return $this; }
    public function setSlug(string $v): self  { $this->slug = $v; return $this; }
    public function setStatus(int $v): self   { $this->status = $v; return $this; }

    public function toArray(): array
    {
        return [
            'id'     => $this->id,
            'uuid'   => $this->uuid,
            'name'   => $this->name,
            'slug'   => $this->slug,
            'status' => $this->status,
        ];
    }
}
