<?php

/*
 * This file is part of the VitiCore 2.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Depot\Model;

use CpCreation\VitiCore\Behavior\HasImage;
use CpCreation\VitiCore\Behavior\HasTranslatable;
use CpCreation\VitiCore\Behavior\Impl\Image as ImageBehavior;
use CpCreation\VitiCore\Behavior\Impl\Translatable;
use CpCreation\VitiCore\Media\Model\Image;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

#[ORM\Entity(repositoryClass: 'CpCreation\VitiCore\Depot\Repository\CategoryRepository')]
#[ORM\Table(name: 'depot_category')]
#[ORM\HasLifecycleCallbacks]
class Category implements HasTranslatable, HasImage
{
    use ImageBehavior;
    use Translatable;

    #[ORM\Id]
    #[ORM\Column(type: 'uuid')]
    #[ORM\GeneratedValue(strategy: 'NONE')]
    private UuidInterface $id;

    #[Gedmo\SortablePosition]
    #[ORM\Column(type: 'integer', nullable: true)]
    private ?int $position = null;

    #[ORM\Column(type: 'string', length: 7, nullable: true)]
    private ?string $color = null;

    /**
     * @var Collection<int, Depot>
     */
    #[ORM\OneToMany(targetEntity: Depot::class, mappedBy: 'category')]
    #[ORM\OrderBy(['position' => 'ASC'])]
    private Collection $depots;

    public function __construct()
    {
        $this->id = Uuid::uuid4();
        $this->depots = new ArrayCollection();
    }

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

    public function getPosition(): ?int
    {
        return $this->position;
    }

    public function setPosition(?int $position): void
    {
        $this->position = $position;
    }

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

    public function setColor(?string $color): void
    {
        $this->color = $color;
    }

    public function getIcon(): ?Image
    {
        return $this->getImage();
    }

    public function setIcon(?Image $icon): void
    {
        $this->setImage($icon);
    }

    /**
     * @return Collection<int, Depot>
     */
    public function getDepots(): Collection
    {
        return $this->depots;
    }
}
