<?php

namespace App\Entity;

use App\Repository\ReservationArticleRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ReservationArticleRepository::class)]
class ReservationArticle
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    private ?string $reference = null;

    #[ORM\ManyToOne(inversedBy: 'reservationArticles')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Article $article = null;

    #[ORM\ManyToOne(inversedBy: 'reservationArticles')]
    #[ORM\JoinColumn(nullable: false)]
    private ?User $client = null;

    #[ORM\ManyToOne(inversedBy: 'reservationArticles')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Societe $societe = null;

    #[ORM\Column]
    private ?int $quantite = null;

    #[ORM\Column]
    private ?float $prix = null;

    #[ORM\Column]
    private ?float $avance = null;

    #[ORM\Column]
    private ?int $frais = null;

    #[ORM\Column(type: Types::DATETIME_MUTABLE)]
    private ?\DateTimeInterface $date_add = null;

    #[ORM\Column]
    private array $etat = [];

    #[ORM\OneToOne(mappedBy: 'reservationArticle', cascade: ['persist', 'remove'])]
    private ?ReservationArticleValidation $reservationArticleValidation = null;

    public function __construct()
    {
        $this->date_add = new \DateTime();
        $this->generateReference();
    }

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

    public function setReference(string $reference): static
    {
        $this->reference = $reference;

        return $this;
    }

    public function getArticle(): ?Article
    {
        return $this->article;
    }

    public function setArticle(?Article $article): static
    {
        $this->article = $article;
        $this->societe = $article->getSociete();
        return $this;
    }

    public function getClient(): ?User
    {
        return $this->client;
    }

    public function setClient(?User $client): static
    {
        $this->client = $client;

        return $this;
    }

    public function getQuantite(): ?int
    {
        return $this->quantite;
    }

    public function setQuantite(int $quantite): static
    {
        $this->quantite = $quantite;

        return $this;
    }

    public function getPrix(): ?float
    {
        return $this->prix;
    }

    public function setPrix(float $prix): static
    {
        $this->prix = $prix;

        return $this;
    }

    public function getAvance(): ?float
    {
        return $this->avance;
    }

    public function setAvance(float $avance): static
    {
        $this->avance = $avance;

        return $this;
    }

    public function getFrais(): ?int
    {
        return $this->frais;
    }

    public function setFrais(int $frais): static
    {
        $this->frais = $frais;

        return $this;
    }

    public function getDateAdd(): ?\DateTimeInterface
    {
        return $this->date_add;
    }

    public function setDateAdd(\DateTimeInterface $date_add): static
    {
        $this->date_add = $date_add;

        return $this;
    }

    public function getEtat(): array
    {
        return $this->etat;
    }

    public function setEtat(array $etat): static
    {
        $this->etat = $etat;

        return $this;
    }

    public function addEtat(string $key, string $str): static
    {
        $this->etat[$key] = $str;

        return $this;
    }

    public function getType(): string
    {
        return "ReservationArticle";
    }

    public function generateReference():static
    {
        $code1 = random_int(1000, 9999);
        $code2 = random_int(1000, 9999);
        $code3 = random_int(1000, 9999);
        $code4 = random_int(1000, 9999);

        $this->reference = "$code1-$code2-$code3-$code4";
        return $this;
    }

    public function getReservationArticleValidation(): ?ReservationArticleValidation
    {
        return $this->reservationArticleValidation;
    }

    public function setReservationArticleValidation(ReservationArticleValidation $reservationArticleValidation): static
    {
        // set the owning side of the relation if necessary
        if ($reservationArticleValidation->getReservationArticle() !== $this) {
            $reservationArticleValidation->setReservationArticle($this);
        }

        $this->reservationArticleValidation = $reservationArticleValidation;

        return $this;
    }

    public function getSociete(): ?Societe
    {
        return $this->societe;
    }

    public function setSociete(?Societe $societe): static
    {
        $this->societe = $societe;

        return $this;
    }

}
