<?php

namespace App\Entity;

use App\Repository\AnnonceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

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

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

    #[ORM\Column(type: Types::TEXT)]
    private ?string $description = null;

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

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

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

    #[ORM\Column(type: Types::SMALLINT)]
    private ?int $largeur = null;

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

    #[ORM\Column]
    private ?bool $active = null;

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

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false)]
    private ?User $create_by = null;

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

    #[ORM\ManyToOne(inversedBy: 'annonces')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Categorie $categorie = null;

    #[ORM\OneToMany(mappedBy: 'annonce', targetEntity: Position::class)]
    private Collection $positions;

    #[ORM\OneToMany(mappedBy: 'annonce', targetEntity: Affichage::class)]
    private Collection $affichages;

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

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

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

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

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

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

    #[ORM\Column]
    private ?bool $complet = null;

    #[ORM\OneToMany(mappedBy: 'annonce', targetEntity: CommentAnnonce::class)]
    #[ORM\OrderBy(['id' => 'DESC'])]
    private Collection $commentAnnonces;

    public function __construct()
    {
        $this->active = true;
        $this->complet = false;
        $this->date_add = new \DateTime();
        $this->date_update = new \DateTime();
        $this->positions = new ArrayCollection();
        $this->affichages = new ArrayCollection();
        $this->commentAnnonces = new ArrayCollection();
    }

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

    public function getTitre(): ?string
    {
        return $this->titre;
    }

    public function setTitre(string $titre): self
    {
        $this->titre = $titre;

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(string $description): self
    {
        $this->description = $description;

        return $this;
    }

    public function getPrixMarche(): ?float
    {
        return $this->prix_marche;
    }

    public function setPrixMarche(?float $prix_marche): self
    {
        $this->prix_marche = $prix_marche;

        return $this;
    }

    public function getPrixPromo(): ?float
    {
        return $this->prix_promo;
    }

    public function setPrixPromo(float $prix_promo): self
    {
        $this->prix_promo = $prix_promo;

        return $this;
    }

    public function getPourcentageReduction(): ?float
    {
        return $this->pourcentage_reduction;
    }

    public function setPourcentageReduction(?float $pourcentage_reduction): self
    {
        $this->pourcentage_reduction = $pourcentage_reduction;

        return $this;
    }

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

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

        return $this;
    }

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

    public function setActive(bool $active): self
    {
        $this->active = $active;

        return $this;
    }

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

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

        return $this;
    }

    public function getCreateBy(): ?User
    {
        return $this->create_by;
    }

    public function setCreateBy(?User $create_by): self
    {
        $this->create_by = $create_by;

        return $this;
    }

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

    public function setDateUpdate(\DateTimeInterface $date_update): static
    {
        $this->date_update = $date_update;

        return $this;
    }

    public function getCategorie(): ?Categorie
    {
        return $this->categorie;
    }

    public function setCategorie(?Categorie $categorie): static
    {
        $this->categorie = $categorie;

        return $this;
    }

    /**
     * @return Collection<int, Position>
     */
    public function getPositions(): Collection
    {
        return $this->positions;
    }

    public function addPosition(Position $position): static
    {
        if (!$this->positions->contains($position)) {
            $this->positions->add($position);
            $position->setAnnonce($this);
        }

        return $this;
    }

    public function removePosition(Position $position): static
    {
        if ($this->positions->removeElement($position)) {
            // set the owning side to null (unless already changed)
            if ($position->getAnnonce() === $this) {
                $position->setAnnonce(null);
            }
        }

        return $this;
    }

    public function getLargeur(): ?int
    {
        return $this->largeur;
    }

    public function setLargeur(int $largeur): static
    {
        $this->largeur = $largeur;

        return $this;
    }

    public function getDimension(): ?string
    {
        if($this->largeur == 1){
            return "1/4 (438 * 240) pixels";
        }elseif($this->largeur == 2){
            return "2/4 (876 * 240) pixels";
        }elseif($this->largeur == 3){
            return "3/4 (1314 * 240) pixels";
        }elseif($this->largeur == 4){
            return "4/4 (1752 * 240) pixels";
        }
    }

    public function getDimensionWidth(): ?string
    {
        if($this->largeur == 1){
            return 438;
        }elseif($this->largeur == 2){
            return 876;
        }elseif($this->largeur == 3){
            return 1314;
        }elseif($this->largeur == 4){
            return 1752;
        }
    }

    /**
     * @return Collection<int, Affichage>
     */
    public function getAffichages(): Collection
    {
        return $this->affichages;
    }

    public function addAffichage(Affichage $affichage): static
    {
        if (!$this->affichages->contains($affichage)) {
            $this->affichages->add($affichage);
            $affichage->setAnnonce($this);
        }

        return $this;
    }

    public function removeAffichage(Affichage $affichage): static
    {
        if ($this->affichages->removeElement($affichage)) {
            // set the owning side to null (unless already changed)
            if ($affichage->getAnnonce() === $this) {
                $affichage->setAnnonce(null);
            }
        }

        return $this;
    }

    public function getImageHome(): ?string
    {
        return $this->image_home;
    }

    public function setImageHome(?string $image_home): static
    {
        $this->image_home = $image_home;

        return $this;
    }

    public function getImageSearch(): ?string
    {
        return $this->image_search;
    }

    public function setImageSearch(?string $image_search): static
    {
        $this->image_search = $image_search;

        return $this;
    }

    public function getImageDetail1(): ?string
    {
        return $this->image_detail_1;
    }

    public function setImageDetail1(?string $image_detail_1): static
    {
        $this->image_detail_1 = $image_detail_1;

        return $this;
    }

    public function getImageDetail2(): ?string
    {
        return $this->image_detail_2;
    }

    public function setImageDetail2(?string $image_detail_2): static
    {
        $this->image_detail_2 = $image_detail_2;

        return $this;
    }

    public function getImageDetail3(): ?string
    {
        return $this->image_detail_3;
    }

    public function setImageDetail3(?string $image_detail_3): static
    {
        $this->image_detail_3 = $image_detail_3;

        return $this;
    }

    public function getImageDetail4(): ?string
    {
        return $this->image_detail_4;
    }

    public function setImageDetail4(?string $image_detail_4): static
    {
        $this->image_detail_4 = $image_detail_4;

        return $this;
    }

    public function getAllImage(): ?array
    {
        $ListImg = [];
        
        if($this->image_search) $ListImg[] = $this->image_search;
        if($this->image_home) $ListImg[] = $this->image_home;
        if($this->image_detail_1) $ListImg[] = $this->image_detail_1;
        if($this->image_detail_2) $ListImg[] = $this->image_detail_2;
        if($this->image_detail_3) $ListImg[] = $this->image_detail_3;
        if($this->image_detail_4) $ListImg[] = $this->image_detail_4;

        return $ListImg;
    }

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

    public function setComplet(bool $complet): static
    {
        $this->complet = $complet;

        return $this;
    }


    public function checkComplet(): static
    {
        if( ($this->image_home!="") && 
            ($this->image_search!="") && 
            ($this->image_detail_1!="") 
        ) 
        {
            $this->complet = true;
        }else{
            $this->complet = false;
        }
        return $this;
    }

    /**
     * @return Collection<int, CommentAnnonce>
     */
    public function getCommentAnnonces(): Collection
    {
        return $this->commentAnnonces;
    }

    public function addCommentAnnonce(CommentAnnonce $commentAnnonce): static
    {
        if (!$this->commentAnnonces->contains($commentAnnonce)) {
            $this->commentAnnonces->add($commentAnnonce);
            $commentAnnonce->setAnnonce($this);
        }

        return $this;
    }

    public function removeCommentAnnonce(CommentAnnonce $commentAnnonce): static
    {
        if ($this->commentAnnonces->removeElement($commentAnnonce)) {
            // set the owning side to null (unless already changed)
            if ($commentAnnonce->getAnnonce() === $this) {
                $commentAnnonce->setAnnonce(null);
            }
        }

        return $this;
    }
}
