<?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\HasDisable;
use CpCreation\VitiCore\Behavior\HasTimestamp;
use CpCreation\VitiCore\Behavior\Impl\Disable;
use CpCreation\VitiCore\Behavior\Impl\SoftDeletable;
use CpCreation\VitiCore\Behavior\Impl\Timestamp;
use CpCreation\VitiCore\Behavior\IsSoftDeletable;
use CpCreation\VitiCore\Product\Repository\ProductPriceCodeRepository;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity(repositoryClass: ProductPriceCodeRepository::class)]
#[ORM\Table(name: 'product_price_code')]
#[ORM\HasLifecycleCallbacks]
class ProductPriceCode implements HasTimestamp, IsSoftDeletable, HasDisable
{
    use Disable;
    use SoftDeletable;
    use Timestamp;

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

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

    #[ORM\ManyToOne(targetEntity: ProductPriceGroup::class, inversedBy: 'codes')]
    #[ORM\JoinColumn(name: 'group_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
    #[Assert\NotBlank]
    private ?ProductPriceGroup $group = null;

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

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

    public function getCode(): ?string
    {
        return $this->code;
    }

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

    public function getGroup(): ?ProductPriceGroup
    {
        return $this->group;
    }

    public function setGroup(?ProductPriceGroup $group): void
    {
        $this->group = $group;
    }
}
