<?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\Translation;

use CpCreation\VitiCore\Behavior\Impl\Translation;
use CpCreation\VitiCore\Product\Model\ProductTypeOption;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

#[ORM\Entity]
#[ORM\Table(name: 'product_option_translation')]
class ProductTypeOptionTranslation implements TranslationInterface
{
    use Translation;

    /**
     * L'évènement LoadClassMetaData de TransaltableEventsubscriber ne se lance pas
     * pour ProductTypeTranslation. C'est pour cela que la relation est déclarée ici.
     */
    #[ORM\ManyToOne(
        targetEntity: ProductTypeOption::class,
        inversedBy: 'translations',
        cascade: ['all']
    )]
    #[ORM\JoinColumn(name: 'translatable_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
    protected $translatable;

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

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

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

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

    public function getText(): ?string
    {
        return $this->text;
    }

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