<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity]
class Website
{
    public const TYPE_VITRINE = 'vitrine';
    public const TYPE_ECOMMERCE = 'ecommerce';

    public const STATE_CREATED = 'created';
    public const STATE_INSTALL_PROGRESS = 'install_progress';
    public const STATE_OPEN = 'open';
    public const STATE_SUSPENDED = 'suspended';
    public const STATE_CLOSED = 'closed';

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: Customer::class)]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private Customer $customer;

    #[ORM\Column(length: 255)]
    private string $name;

    #[ORM\Column(length: 36, unique: true)]
    private string $uuid;

    #[ORM\Column(length: 20)]
    private string $type;

    #[ORM\Column(length: 20)]
    private string $state = self::STATE_CREATED;

    #[ORM\Column(length: 10, nullable: true)]
    private ?string $revendeurCode = null;

    #[ORM\Column]
    private \DateTimeImmutable $createdAt;

    #[ORM\Column(nullable: true)]
    private ?\DateTimeImmutable $updatedAt = null;

    public function __construct(Customer $customer, string $name, string $type = self::TYPE_VITRINE)
    {
        $this->customer = $customer;
        $this->name = $name;
        $this->type = $type;
        $this->uuid = Uuid::v4()->toRfc4122();
        $this->createdAt = new \DateTimeImmutable();
    }

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

    public function getCustomer(): Customer
    {
        return $this->customer;
    }

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

    public function setName(string $name): static
    {
        $this->name = $name;

        return $this;
    }

    public function getUuid(): string
    {
        return $this->uuid;
    }

    public function getType(): string
    {
        return $this->type;
    }

    public function setType(string $type): static
    {
        $this->type = $type;

        return $this;
    }

    public function getState(): string
    {
        return $this->state;
    }

    public function setState(string $state): static
    {
        $this->state = $state;
        $this->updatedAt = new \DateTimeImmutable();

        return $this;
    }

    public function isOpen(): bool
    {
        return self::STATE_OPEN === $this->state;
    }

    public function getRevendeurCode(): ?string
    {
        return $this->revendeurCode;
    }

    public function setRevendeurCode(?string $revendeurCode): static
    {
        $this->revendeurCode = $revendeurCode;

        return $this;
    }

    public function getCreatedAt(): \DateTimeImmutable
    {
        return $this->createdAt;
    }

    public function getUpdatedAt(): ?\DateTimeImmutable
    {
        return $this->updatedAt;
    }

    public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }
}
