<?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;

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

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

    #[ORM\ManyToOne(targetEntity: ShippingZone::class, inversedBy: 'counties')]
    #[ORM\JoinColumn(name: 'zone_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
    private ?ShippingZone $zone = null;

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

    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 getZone(): ?ShippingZone
    {
        return $this->zone;
    }

    public function setZone(?ShippingZone $zone = null): void
    {
        $this->zone = $zone;
    }
}
