<?php

namespace App\Entity;

use App\Repository\ContratsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Attribute\Uploadable;
use Vich\UploaderBundle\Mapping\Attribute\UploadableField;

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

    #[ORM\ManyToOne(inversedBy: 'contrats')]
    private ?Customer $customer = null;

    #[ORM\OneToOne(inversedBy: 'contrats', cascade: ['persist', 'remove'])]
    private ?Devis $devis = null;

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

    #[ORM\Column]
    private ?\DateTimeImmutable $createAt = null;

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

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

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

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

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

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

    #[ORM\Column(type: Types::TEXT,nullable: true)]
    private ?string $details = null;

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

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

    #[ORM\Column(type: Types::TEXT,nullable: true)]
    private ?string $access = null;

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

    #[ORM\Column(type: Types::TEXT,nullable: true)]
    private ?string $notes = null;

    #[ORM\Column(options: ['default' => false])]
    private ?bool $isSigned = false;

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

    /**
     * @var Collection<int, ContratsPayments>
     */
    #[ORM\OneToMany(targetEntity: ContratsPayments::class, mappedBy: 'contrat')]
    private Collection $contratsPayments;

    #[ORM\Column]
    private ?\DateTimeImmutable $dateAt = null;

    #[ORM\Column]
    private ?\DateTimeImmutable $endAt = null;

    /**
     * @var Collection<int, ContratsLine>
     */
    #[ORM\OneToMany(targetEntity: ContratsLine::class, mappedBy: 'contrat')]
    private Collection $contratsLines;

    /**
     * @var Collection<int, ContratsOption>
     */
    #[ORM\OneToMany(targetEntity: ContratsOption::class, mappedBy: 'contrat')]
    private Collection $contratsOptions;


    #[UploadableField(mapping: 'contrat_file', fileNameProperty: 'devisFileName', size: 'devisFileSize')]
    private ?File $devisFile = null;
    #[ORM\Column(nullable: true)]
    private ?string $devisFileName = null;
    #[ORM\Column(nullable: true)]
    private ?int $devisFileSize = null;

    #[UploadableField(mapping: 'contrat_docuseal', fileNameProperty: 'devisDocuSealFileName', size: 'devisDocuSealFileSize')]
    private ?File $devisDocuSealFile = null;
    #[ORM\Column(nullable: true)]
    private ?string $devisDocuSealFileName = null;
    #[ORM\Column(nullable: true)]
    private ?int $devisDocuSealFileSize = null;

    #[UploadableField(mapping: 'contrat_signed', fileNameProperty: 'devisSignedFileName', size: 'devisSignedFileSize')]
    private ?File $devisSignFile = null;
    #[ORM\Column(nullable: true)]
    private ?string $devisSignedFileName = null;
    #[ORM\Column(nullable: true)]
    private ?int $devisSignedFileSize = null;

    #[UploadableField(mapping: 'contrat_audit', fileNameProperty: 'devisAuditFileName', size: 'devisAuditFileSize')]
    private ?File $devisAuditFile = null;
    #[ORM\Column(nullable: true)]
    private ?string $devisAuditFileName = null;
    #[ORM\Column(nullable: true)]
    private ?int $devisAuditFileSize = null;


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

    /**
     * @var Collection<int, ProductReserve>
     */
    #[ORM\OneToMany(targetEntity: ProductReserve::class, mappedBy: 'contrat')]
    private Collection $productReserves;

    #[ORM\OneToOne(mappedBy: 'contrat', cascade: ['persist', 'remove'])]
    private ?Facture $facture = null;

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

    #[ORM\Column(length: 50, options: ['default' => 'pending'])]
    private string $reservationState = 'pending';

    #[ORM\OneToOne(mappedBy: 'contrat', cascade: ['persist', 'remove'])]
    private ?EtatLieux $etatLieux = null;

    #[ORM\ManyToOne(inversedBy: 'contrats')]
    private ?Prestaire $prestataire = null;

    public function __construct()
    {
        $this->contratsPayments = new ArrayCollection();
        $this->contratsLines = new ArrayCollection();
        $this->contratsOptions = new ArrayCollection();
        $this->productReserves = new ArrayCollection();
    }

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

    public function getReservationState(): string
    {
        return $this->reservationState;
    }

    public function setReservationState(string $reservationState): static
    {
        $this->reservationState = $reservationState;

        return $this;
    }

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

    public function setCustomer(?Customer $customer): static
    {
        $this->customer = $customer;

        return $this;
    }

    public function getDevis(): ?Devis
    {
        return $this->devis;
    }

    public function setDevis(?Devis $devis): static
    {
        $this->devis = $devis;

        return $this;
    }

    public function getNumReservation(): ?string
    {
        return $this->numReservation;
    }

    public function setNumReservation(string $numReservation): static
    {
        $this->numReservation = $numReservation;

        return $this;
    }

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

    public function setCreateAt(\DateTimeImmutable $createAt): static
    {
        $this->createAt = $createAt;

        return $this;
    }

    public function getAddressEvent(): ?string
    {
        return $this->adressEvent;
    }

    public function setAddressEvent(string $adressEvent): static
    {
        $this->adressEvent = $adressEvent;

        return $this;
    }

    public function getAddress2Event(): ?string
    {
        return $this->adress2Event;
    }

    public function setAddress2Event(?string $adress2Event): static
    {
        $this->adress2Event = $adress2Event;

        return $this;
    }

    public function getAddress3Event(): ?string
    {
        return $this->adress3Event;
    }

    public function setAddress3Event(?string $adress3Event): static
    {
        $this->adress3Event = $adress3Event;

        return $this;
    }

    public function getZipCodeEvent(): ?string
    {
        return $this->zipCodeEvent;
    }

    public function setZipCodeEvent(string $zipCode): static
    {
        $this->zipCodeEvent = $zipCode;

        return $this;
    }

    public function getTownEvent(): ?string
    {
        return $this->townEvent;
    }

    public function setTownEvent(string $town): static
    {
        $this->townEvent = $town;

        return $this;
    }

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

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

        return $this;
    }

    public function getDetails(): ?string
    {
        return $this->details;
    }

    public function setDetails(?string $details): static
    {
        $this->details = $details;

        return $this;
    }

    public function getTypeSol(): ?string
    {
        return $this->typeSol;
    }

    public function setTypeSol(string $typeSol): static
    {
        $this->typeSol = $typeSol;

        return $this;
    }

    public function getPente(): ?string
    {
        return $this->pente;
    }

    public function setPente(string $pente): static
    {
        $this->pente = $pente;

        return $this;
    }

    public function getAccess(): ?string
    {
        return $this->access;
    }

    public function setAccess(string $access): static
    {
        $this->access = $access;

        return $this;
    }

    public function getDistancePower(): ?float
    {
        return $this->distancePower;
    }

    public function setDistancePower(float $distancePower): static
    {
        $this->distancePower = $distancePower;

        return $this;
    }

    public function getNotes(): ?string
    {
        return $this->notes;
    }

    public function setNotes(string $notes): static
    {
        $this->notes = $notes;

        return $this;
    }

    public function isSigned(): ?bool
    {
        return $this->isSigned;
    }

    public function setIsSigned(bool $isSigned): static
    {
        $this->isSigned = $isSigned;

        return $this;
    }

    public function getSignID(): ?string
    {
        return $this->signID;
    }

    public function setSignID(?string $signID): static
    {
        $this->signID = $signID;

        return $this;
    }

    /**
     * @return Collection<int, ContratsPayments>
     */
    public function getContratsPayments(): Collection
    {
        return $this->contratsPayments;
    }

    public function addContratsPayment(ContratsPayments $contratsPayment): static
    {
        if (!$this->contratsPayments->contains($contratsPayment)) {
            $this->contratsPayments->add($contratsPayment);
            $contratsPayment->setContrat($this);
        }

        return $this;
    }

    public function removeContratsPayment(ContratsPayments $contratsPayment): static
    {
        if ($this->contratsPayments->removeElement($contratsPayment)) {
            // set the owning side to null (unless already changed)
            if ($contratsPayment->getContrat() === $this) {
                $contratsPayment->setContrat(null);
            }
        }

        return $this;
    }

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

    public function setDateAt(\DateTimeImmutable $dateAt): static
    {
        $this->dateAt = $dateAt;

        return $this;
    }

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

    public function setEndAt(\DateTimeImmutable $endAt): static
    {
        $this->endAt = $endAt;

        return $this;
    }

    /**
     * @return Collection<int, ContratsLine>
     */
    public function getContratsLines(): Collection
    {
        return $this->contratsLines;
    }

    public function addContratsLine(ContratsLine $contratsLine): static
    {
        if (!$this->contratsLines->contains($contratsLine)) {
            $this->contratsLines->add($contratsLine);
            $contratsLine->setContrat($this);
        }

        return $this;
    }

    public function removeContratsLine(ContratsLine $contratsLine): static
    {
        if ($this->contratsLines->removeElement($contratsLine)) {
            // set the owning side to null (unless already changed)
            if ($contratsLine->getContrat() === $this) {
                $contratsLine->setContrat(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, ContratsOption>
     */
    public function getContratsOptions(): Collection
    {
        return $this->contratsOptions;
    }

    public function addContratsOption(ContratsOption $contratsOption): static
    {
        if (!$this->contratsOptions->contains($contratsOption)) {
            $this->contratsOptions->add($contratsOption);
            $contratsOption->setContrat($this);
        }

        return $this;
    }

    public function removeContratsOption(ContratsOption $contratsOption): static
    {
        if ($this->contratsOptions->removeElement($contratsOption)) {
            // set the owning side to null (unless already changed)
            if ($contratsOption->getContrat() === $this) {
                $contratsOption->setContrat(null);
            }
        }

        return $this;
    }

    /**
     * @return File|null
     */
    public function getDevisSignFile(): ?File
    {
        return $this->devisSignFile;
    }

    /**
     * @return int|null
     */
    public function getDevisSignedFileSize(): ?int
    {
        return $this->devisSignedFileSize;
    }

    /**
     * @return string|null
     */
    public function getDevisSignedFileName(): ?string
    {
        return $this->devisSignedFileName;
    }

    /**
     * @return int|null
     */
    public function getDevisFileSize(): ?int
    {
        return $this->devisFileSize;
    }

    /**
     * @return string|null
     */
    public function getDevisFileName(): ?string
    {
        return $this->devisFileName;
    }

    /**
     * @return File|null
     */
    public function getDevisFile(): ?File
    {
        return $this->devisFile;
    }

    /**
     * @return int|null
     */
    public function getDevisDocuSealFileSize(): ?int
    {
        return $this->devisDocuSealFileSize;
    }

    /**
     * @return string|null
     */
    public function getDevisDocuSealFileName(): ?string
    {
        return $this->devisDocuSealFileName;
    }

    /**
     * @return File|null
     */
    public function getDevisDocuSealFile(): ?File
    {
        return $this->devisDocuSealFile;
    }

    /**
     * @return int|null
     */
    public function getDevisAuditFileSize(): ?int
    {
        return $this->devisAuditFileSize;
    }

    /**
     * @return string|null
     */
    public function getDevisAuditFileName(): ?string
    {
        return $this->devisAuditFileName;
    }

    /**
     * @return File|null
     */
    public function getDevisAuditFile(): ?File
    {
        return $this->devisAuditFile;
    }

    /**
     * @return \DateTimeImmutable|null
     */
    public function getUpdateAt(): ?\DateTimeImmutable
    {
        return $this->updateAt;
    }

    /**
     * @param int|null $devisAuditFileSize
     */
    public function setDevisAuditFileSize(?int $devisAuditFileSize): void
    {
        $this->devisAuditFileSize = $devisAuditFileSize;
    }

    /**
     * @param string|null $devisFileName
     */
    public function setDevisFileName(?string $devisFileName): void
    {
        $this->devisFileName = $devisFileName;
    }

    /**
     * @param string|null $devisDocuSealFileName
     */
    public function setDevisDocuSealFileName(?string $devisDocuSealFileName): void
    {
        $this->devisDocuSealFileName = $devisDocuSealFileName;
    }

    /**
     * @param int|null $devisDocuSealFileSize
     */
    public function setDevisDocuSealFileSize(?int $devisDocuSealFileSize): void
    {
        $this->devisDocuSealFileSize = $devisDocuSealFileSize;
    }

    /**
     * @param int|null $devisFileSize
     */
    public function setDevisFileSize(?int $devisFileSize): void
    {
        $this->devisFileSize = $devisFileSize;
    }

    /**
     * @param string|null $devisSignedFileName
     */
    public function setDevisSignedFileName(?string $devisSignedFileName): void
    {
        $this->devisSignedFileName = $devisSignedFileName;
    }

    /**
     * @param int|null $devisSignedFileSize
     */
    public function setDevisSignedFileSize(?int $devisSignedFileSize): void
    {
        $this->devisSignedFileSize = $devisSignedFileSize;
    }

    /**
     * @param \DateTimeImmutable|null $updateAt
     */
    public function setUpdateAt(?\DateTimeImmutable $updateAt): void
    {
        $this->updateAt = $updateAt;
    }

    /**
     * @param File|null $devisSignFile
     */
    public function setDevisSignFile(?File $devisSignFile): void
    {
        $this->devisSignFile = $devisSignFile;
    }

    /**
     * @param string|null $adress2Event
     */
    public function setAdress2Event(?string $adress2Event): void
    {
        $this->adress2Event = $adress2Event;
    }

    /**
     * @param string|null $adress3Event
     */
    public function setAdress3Event(?string $adress3Event): void
    {
        $this->adress3Event = $adress3Event;
    }

    /**
     * @param string|null $adressEvent
     */
    public function setAdressEvent(?string $adressEvent): void
    {
        $this->adressEvent = $adressEvent;
    }

    /**
     * @param Collection $contratsLines
     */
    public function setContratsLines(Collection $contratsLines): void
    {
        $this->contratsLines = $contratsLines;
    }

    /**
     * @param Collection $contratsOptions
     */
    public function setContratsOptions(Collection $contratsOptions): void
    {
        $this->contratsOptions = $contratsOptions;
    }

    /**
     * @param Collection $contratsPayments
     */
    public function setContratsPayments(Collection $contratsPayments): void
    {
        $this->contratsPayments = $contratsPayments;
    }

    /**
     * @param File|null $devisAuditFile
     */
    public function setDevisAuditFile(?File $devisAuditFile): void
    {
        $this->devisAuditFile = $devisAuditFile;
    }

    /**
     * @param string|null $devisAuditFileName
     */
    public function setDevisAuditFileName(?string $devisAuditFileName): void
    {
        $this->devisAuditFileName = $devisAuditFileName;
    }

    /**
     * @param File|null $devisDocuSealFile
     */
    public function setDevisDocuSealFile(?File $devisDocuSealFile): void
    {
        $this->devisDocuSealFile = $devisDocuSealFile;
    }

    /**
     * @param File|null $devisFile
     */
    public function setDevisFile(?File $devisFile): void
    {
        $this->devisFile = $devisFile;
    }

    /**
     * @return string|null
     */
    public function getAdress2Event(): ?string
    {
        return $this->adress2Event;
    }

    /**
     * @return string|null
     */
    public function getAdress3Event(): ?string
    {
        return $this->adress3Event;
    }

    /**
     * @return string|null
     */
    public function getAdressEvent(): ?string
    {
        return $this->adressEvent;
    }

    /**
     * @return Collection<int, ProductReserve>
     */
    public function getProductReserves(): Collection
    {
        return $this->productReserves;
    }

    public function addProductReserf(ProductReserve $productReserf): static
    {
        if (!$this->productReserves->contains($productReserf)) {
            $this->productReserves->add($productReserf);
            $productReserf->setContrat($this);
        }

        return $this;
    }

    public function removeProductReserf(ProductReserve $productReserf): static
    {
        if ($this->productReserves->removeElement($productReserf)) {
            // set the owning side to null (unless already changed)
            if ($productReserf->getContrat() === $this) {
                $productReserf->setContrat(null);
            }
        }

        return $this;
    }

    public function getFacture(): ?Facture
    {
        return $this->facture;
    }

    public function setFacture(?Facture $facture): static
    {
        // unset the owning side of the relation if necessary
        if ($facture === null && $this->facture !== null) {
            $this->facture->setContrat(null);
        }

        // set the owning side of the relation if necessary
        if ($facture !== null && $facture->getContrat() !== $this) {
            $facture->setContrat($this);
        }

        $this->facture = $facture;

        return $this;
    }

    public function getCautionState(): ?string
    {
        return $this->cautionState;
    }

    public function setCautionState(?string $cautionState): static
    {
        $this->cautionState = $cautionState;

        return $this;
    }

    public function getEtatLieux(): ?EtatLieux
    {
        return $this->etatLieux;
    }

    public function setEtatLieux(?EtatLieux $etatLieux): static
    {
        // unset the owning side of the relation if necessary
        if ($etatLieux === null && $this->etatLieux !== null) {
            $this->etatLieux->setContrat(null);
        }

        // set the owning side of the relation if necessary
        if ($etatLieux !== null && $etatLieux->getContrat() !== $this) {
            $etatLieux->setContrat($this);
        }

        $this->etatLieux = $etatLieux;

        return $this;
    }

    public function getPrestataire(): ?Prestaire
    {
        return $this->prestataire;
    }

    public function setPrestataire(?Prestaire $prestataire): static
    {
        $this->prestataire = $prestataire;

        return $this;
    }

    public function isCaution()
    {
        return $this->contratsPayments->filter(function (ContratsPayments $contratsPayments){
            return $contratsPayments->getType() == "caution" && $contratsPayments->getState() == "complete";
        })->first() instanceof ContratsPayments;
    }
    public function isAccompte()
    {
        return $this->contratsPayments->filter(function (ContratsPayments $contratsPayments){
            return $contratsPayments->getType() == "accompte" && $contratsPayments->getState() == "complete";
        })->first() instanceof ContratsPayments;
    }
    public function isSolde()
    {
        return $this->contratsPayments->filter(function (ContratsPayments $contratsPayments){
            return $contratsPayments->getType() == "solde" && $contratsPayments->getState() == "complete";
        })->first() instanceof ContratsPayments;
    }

}
