<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Shop\Model\Translation;

use CpCreation\VitiCore\Behavior\Impl\Translation;
use CpCreation\VitiCore\Shop\Model\InformationBlock;
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;
use Symfony\Component\Validator\Context\ExecutionContextInterface;

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

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

    #[ORM\Column(type: 'string', length: 255)]
    #[Assert\NotBlank]
    private ?string $title = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $description = null;

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

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

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

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

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

    public function getTitle(): ?string
    {
        return $this->title;
    }

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

    public function getDescription(): ?string
    {
        return $this->description;
    }

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

    public function getButtonLabel(): ?string
    {
        return $this->buttonLabel;
    }

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

    public function getModalTitle(): ?string
    {
        return $this->modalTitle;
    }

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

    public function getModalDescription(): ?string
    {
        return $this->modalDescription;
    }

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

    #[Assert\Callback]
    public function validateButtonLabel(ExecutionContextInterface $context): void
    {
        $translatable = $this->getTranslatable();

        if (!$translatable instanceof InformationBlock) {
            return;
        }

        if (InformationBlock::ACTION_NONE === $translatable->getActionType()) {
            return;
        }

        if ('' !== trim((string) $this->buttonLabel)) {
            return;
        }

        $context->buildViolation('Le libellé du bouton est obligatoire lorsqu’un bouton est activé.')
            ->atPath('buttonLabel')
            ->addViolation();
    }
}
