<?php

namespace App\Entity;

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

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

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

    #[ORM\ManyToOne(inversedBy: 'reservationServices')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Service $service = null;

    #[ORM\ManyToOne(inversedBy: 'reservationServices')]
    private ?User $client = null;

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

    #[ORM\OneToOne(inversedBy: 'reservationService', cascade: ['persist', 'remove'])]
    #[ORM\JoinColumn(nullable: false)]
    private ?ServiceRdvReservation $serviceRdvReservation = null;

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

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

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

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

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

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

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

    #[ORM\OneToOne(mappedBy: 'reservationService', cascade: ['persist', 'remove'])]
    private ?ReservationServiceValidation $reservationServiceValidation = 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 getService(): ?Service
    {
        return $this->service;
    }

    public function setService(?Service $service): static
    {
        $this->service = $service;
        $this->societe = $service->getSociete();
        return $this;
    }

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

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

        return $this;
    }

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

    public function setDateRdv(\DateTimeInterface $date_rdv): static
    {
        $this->date_rdv = $date_rdv;

        return $this;
    }

    public function getServiceRdvReservation(): ?ServiceRdvReservation
    {
        return $this->serviceRdvReservation;
    }

    public function setServiceRdvReservation(ServiceRdvReservation $serviceRdvReservation): static
    {
        $this->serviceRdvReservation = $serviceRdvReservation;

        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(): ?float
    {
        return $this->frais;
    }

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

        return $this;
    }

    public function getData(): ?array
    {
        return $this->data;
    }

    public function setData(?array $data): static
    {
        $this->data = $data;

        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 "ReservationService";
    }

    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 getReservationServiceValidation(): ?ReservationServiceValidation
    {
        return $this->reservationServiceValidation;
    }

    public function setReservationServiceValidation(ReservationServiceValidation $reservationServiceValidation): static
    {
        // set the owning side of the relation if necessary
        if ($reservationServiceValidation->getReservationService() !== $this) {
            $reservationServiceValidation->setReservationService($this);
        }

        $this->reservationServiceValidation = $reservationServiceValidation;

        return $this;
    }

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

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

        return $this;
    }

}
