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

#[ORM\Entity(repositoryClass: ProductPriceGroupRepository::class)]
#[ORM\Table(name: 'product_price_group')]
#[ORM\HasLifecycleCallbacks]
class ProductPriceGroup implements HasTimestamp, IsSoftDeletable
{
    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 $name = null;

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

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

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

    /**
     * @var Collection<int, ProductPrice>
     */
    #[ORM\OneToMany(targetEntity: ProductPrice::class, cascade: ['remove'], mappedBy: 'group')]
    protected Collection $prices;

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

    /**
     * @var Collection<int, ProductPriceCode>
     */
    #[ORM\OneToMany(targetEntity: ProductPriceCode::class, cascade: ['remove'], mappedBy: 'group')]
    private Collection $codes;

    public function __construct()
    {
        $this->id = Uuid::uuid4();
        $this->byDefault = false;
        $this->viewHT = false;
        $this->freeShipping = false;
        $this->prices = new ArrayCollection();
        $this->codes = new ArrayCollection();
    }

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

    public function getName(): ?string
    {
        return $this->name;
    }

    public function isByDefault(): bool
    {
        return $this->byDefault;
    }

    public function setByDefault(bool $byDefault): void
    {
        $this->byDefault = $byDefault;
    }

    public function isViewHT(): bool
    {
        return $this->viewHT;
    }

    public function isFreeShipping(): bool
    {
        return $this->freeShipping;
    }

    public function setFreeShipping(bool $freeShipping): void
    {
        $this->freeShipping = $freeShipping;
    }

    public function setViewHT(bool $viewHT): void
    {
        $this->viewHT = $viewHT;
    }

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

    public function getPosition(): ?int
    {
        return $this->position;
    }

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

    /**
     * @return Collection<int, ProductPriceCode>
     */
    public function getCodes(): Collection
    {
        return $this->codes;
    }

    /**
     * @return Collection<int, ProductPrice>
     */
    public function getPrices(): Collection
    {
        return $this->prices;
    }
}
