<?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 CpCreation\VitiCore\Behavior\HasTimestamp;
use CpCreation\VitiCore\Behavior\Impl\Timestamp;
use CpCreation\VitiCore\Product\Model\ProductType;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Table(name: 'shop_shop_config_multiple')]
#[ORM\HasLifecycleCallbacks]
#[ORM\Entity(repositoryClass: 'CpCreation\VitiCore\Shop\Repository\ShopConfigRepository')]
class ShopConfigMultiple implements HasTimestamp
{
    use Timestamp;

    #[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')]
    #[Assert\NotBlank]
    private ?int $qtyAt = null;

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

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

    #[ORM\ManyToMany(targetEntity: ShippingZone::class)]
    #[Assert\Count(min: 1, minMessage: 'Vous devez ajouter au moins une zone')]
    private Collection $zones;

    #[ORM\ManyToMany(targetEntity: ProductType::class)]
    #[Assert\Count(min: 1, minMessage: 'Vous devez ajouter au moins un type')]
    private Collection $types;

    #[ORM\ManyToOne(targetEntity: ShopConfig::class, inversedBy: 'multiples')]
    private ?ShopConfig $config = null;

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

    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 getMultiple(): ?int
    {
        return $this->multiple;
    }

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

    public function getConfig(): ?ShopConfig
    {
        return $this->config;
    }

    public function setConfig(?ShopConfig $config): void
    {
        $this->config = $config;
    }

    public function addType(ProductType $productType): self
    {
        $this->types[] = $productType;

        return $this;
    }

    public function removeType(ProductType $productType): void
    {
        $this->types->removeElement($productType);
    }

    public function getTypes(): Collection
    {
        return $this->types;
    }

    public function isMinimum(): bool
    {
        return $this->minimum;
    }

    public function setMinimum(bool $minimum): void
    {
        $this->minimum = $minimum;
    }

    public function addZone(ShippingZone $zone): self
    {
        $this->zones[] = $zone;

        return $this;
    }

    public function removeZone(ShippingZone $zone): void
    {
        $this->zones->removeElement($zone);
    }

    public function getZones(): Collection
    {
        return $this->zones;
    }
}
