<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (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\Product\Model;

use CpCreation\VitiCore\Behavior\HasGroupAvailable;
use CpCreation\VitiCore\Behavior\HasTimestamp;
use CpCreation\VitiCore\Behavior\HasTranslatable;
use CpCreation\VitiCore\Behavior\Impl\GroupAvailable;
use CpCreation\VitiCore\Behavior\Impl\Timestamp;
use CpCreation\VitiCore\Behavior\Impl\Translatable;
use CpCreation\VitiCore\Product\Repository\ProductCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Sortable\Sortable;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

#[ORM\Entity(repositoryClass: ProductCategoryRepository::class)]
#[ORM\Table(name: 'product_category')]
#[ORM\HasLifecycleCallbacks]
class ProductCategory implements HasTimestamp, Sortable, HasTranslatable, HasGroupAvailable
{
    use GroupAvailable;
    use Timestamp;
    use Translatable;

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

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

    #[ORM\Column(type: 'boolean', options: ['default' => 1])]
    private bool $pageCuvee;

    #[ORM\Column(type: 'boolean', options: ['default' => 1])]
    private bool $pageShop;

    #[ORM\Column(type: 'boolean', options: ['default' => 0])]
    private bool $displayEvenWithoutGroupMatch;

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

    public function __construct()
    {
        $this->id = Uuid::uuid4();
        $this->products = new ArrayCollection();
        $this->pageCuvee = true;
        $this->pageShop = true;
        $this->displayEvenWithoutGroupMatch = false;
    }

    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 isPageCuvee(): bool
    {
        return $this->pageCuvee;
    }

    public function setPageCuvee(bool $pageCuvee): void
    {
        $this->pageCuvee = $pageCuvee;
    }

    public function isPageShop(): bool
    {
        return $this->pageShop;
    }

    public function setPageShop(bool $pageShop): void
    {
        $this->pageShop = $pageShop;
    }

    public function isDisplayEvenWithoutGroupMatch(): bool
    {
        return $this->displayEvenWithoutGroupMatch;
    }

    public function setDisplayEvenWithoutGroupMatch(bool $displayEvenWithoutGroupMatch): void
    {
        $this->displayEvenWithoutGroupMatch = $displayEvenWithoutGroupMatch;
    }

    /**
     * @return Collection<int, Product>
     */
    public function getProducts(): Collection
    {
        return $this->products;
    }
}
