<?php

declare(strict_types=1);

/*
 * 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\Product\Model;

use CpCreation\VitiCore\Behavior\HasTranslatable;
use CpCreation\VitiCore\Behavior\Impl\Translatable;
use CpCreation\VitiCore\Product\Model\Translation\ProductTypeOptionTranslation;
use CpCreation\VitiCore\Product\Repository\ProductTypeOptionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity(repositoryClass: ProductTypeOptionRepository::class)]
#[ORM\Table(name: 'product_option')]
#[ORM\HasLifecycleCallbacks]
class ProductTypeOption implements HasTranslatable
{
    use Translatable;

    /**
     * @var Collection<string, TranslationInterface>
     */
    #[Assert\Valid]
    #[ORM\OneToMany(
        targetEntity: ProductTypeOptionTranslation::class,
        mappedBy: 'translatable',
        cascade: ['all'],
        indexBy: 'locale',
        orphanRemoval: true
    )]
    protected $translations;

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

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

    #[ORM\ManyToOne(targetEntity: ProductType::class, inversedBy: 'options')]
    private ?ProductType $productType = null;

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

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

    public function getMultiple(): int
    {
        return $this->multiple;
    }

    public function setMultiple(int $multiple): void
    {
        $this->multiple = $multiple;
    }

    public function getProductType(): ?ProductType
    {
        return $this->productType;
    }

    public function setProductType(?ProductType $productType): void
    {
        $this->productType = $productType;
    }
}
