<?php

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

use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;

#[ORM\Entity(repositoryClass: 'CpCreation\VitiCore\Shop\Repository\ShippingAutoRepository')]
#[ORM\Table(name: 'shop_shipping_auto')]
#[ORM\HasLifecycleCallbacks]
class ShippingAuto
{
    #[ORM\Id]
    #[ORM\Column(type: 'uuid')]
    #[ORM\GeneratedValue(strategy: 'NONE')]
    private UuidInterface $id;

    #[ORM\Column(type: 'integer')]
    #[Assert\NotBlank]
    private ?int $qtyOf = null;

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

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

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

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

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

    #[ORM\Column(type: 'boolean')]
    private bool $hM;

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

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

    public function getQtyOf(): ?int
    {
        return $this->qtyOf;
    }

    public function setQtyOf(?int $qtyOf): void
    {
        $this->qtyOf = $qtyOf;
    }

    public function getQtyAt(): ?int
    {
        return $this->qtyAt;
    }

    public function setQtyAt(?int $qtyAt): void
    {
        $this->qtyAt = $qtyAt;
    }

    public function getPackagePrice(): ?int
    {
        return $this->packagePrice;
    }

    public function setPackagePrice(?int $packagePrice): void
    {
        $this->packagePrice = $packagePrice;
    }

    public function getBottlePrice(): ?int
    {
        return $this->bottlePrice;
    }

    public function setBottlePrice(?int $bottlePrice): void
    {
        $this->bottlePrice = $bottlePrice;
    }

    public function getCounty(): ?string
    {
        return $this->county;
    }

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

    public function getCountry(): ?string
    {
        return $this->country;
    }

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

    public function isHM(): bool
    {
        return $this->hM;
    }

    public function setHM(bool $hM): void
    {
        $this->hM = $hM;
    }

    #[Assert\Callback]
    public function validate(ExecutionContextInterface $context): void
    {
        if (null !== $this->getQtyAt() && null !== $this->getQtyOf() && $this->getQtyAt() <= $this->getQtyOf()) {
            $context->buildViolation('La quantité maximale doit être supérieure à la quantité minimale.')
                ->atPath('qtyAt')
                ->addViolation();
        }
    }
}
