<?php

namespace App\Entity;

use App\Repository\FormulesRepository;
use Cocur\Slugify\Slugify;
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: FormulesRepository::class)]
#[Uploadable]
class Formules
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

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


    #[UploadableField(mapping: 'image_formules', fileNameProperty: 'imageName', size: 'imageSize')]
    private ?File $imageFile = null;
    #[ORM\Column(nullable: true)]
    private ?string $imageName = null;

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

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

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

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

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

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

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

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

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

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

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

    #[ORM\OneToOne(mappedBy: 'formule', cascade: ['persist', 'remove'])]
    private ?FormulesRestriction $formulesRestriction = null;

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

    public function __construct()
    {
        $this->formulesProductIncluses = new ArrayCollection();
        $this->formulesOptionsIncluses = new ArrayCollection();
    }


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

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

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

        return $this;
    }

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

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

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

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

    /**
     * @param \DateTimeImmutable|null $updatedAt
     */
    public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

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

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

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

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

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

        return $this;
    }

    /**
     * @return Collection<int, FormulesProductInclus>
     */
    public function getFormulesProductIncluses(): Collection
    {
        return $this->formulesProductIncluses;
    }

    public function addFormulesProductInclus(FormulesProductInclus $formulesProductInclus): static
    {
        if (!$this->formulesProductIncluses->contains($formulesProductInclus)) {
            $this->formulesProductIncluses->add($formulesProductInclus);
            $formulesProductInclus->setFormules($this);
        }

        return $this;
    }

    public function removeFormulesProductInclus(FormulesProductInclus $formulesProductInclus): static
    {
        if ($this->formulesProductIncluses->removeElement($formulesProductInclus)) {
            // set the owning side to null (unless already changed)
            if ($formulesProductInclus->getFormules() === $this) {
                $formulesProductInclus->setFormules(null);
            }
        }

        return $this;
    }

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

    public function setIsPublish(bool $isPublish): static
    {
        $this->isPublish = $isPublish;

        return $this;
    }

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

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

        return $this;
    }

    public function getPrice1j(): ?float
    {
        return $this->price1j;
    }

    public function setPrice1j(?float $price1j): static
    {
        $this->price1j = $price1j;

        return $this;
    }

    public function getPrice2j(): ?float
    {
        return $this->price2j;
    }

    public function setPrice2j(?float $price2j): static
    {
        $this->price2j = $price2j;

        return $this;
    }

    public function getPrice5j(): ?float
    {
        return $this->price5j;
    }

    public function setPrice5j(?float $price5j): static
    {
        $this->price5j = $price5j;

        return $this;
    }

    public function getCaution(): ?float
    {
        return $this->caution;
    }

    public function setCaution(?float $caution): static
    {
        $this->caution = $caution;

        return $this;
    }

    public function slug()
    {
        $s = new Slugify();
        return $this->id."-".$s->slugify($this->name);

    }

    /**
     * @return Collection<int, FormulesOptionsInclus>
     */
    public function getFormulesOptionsIncluses(): Collection
    {
        return $this->formulesOptionsIncluses;
    }

    public function addFormulesOptionsInclus(FormulesOptionsInclus $formulesOptionsInclus): static
    {
        if (!$this->formulesOptionsIncluses->contains($formulesOptionsInclus)) {
            $this->formulesOptionsIncluses->add($formulesOptionsInclus);
            $formulesOptionsInclus->setFormule($this);
        }

        return $this;
    }

    public function removeFormulesOptionsInclus(FormulesOptionsInclus $formulesOptionsInclus): static
    {
        if ($this->formulesOptionsIncluses->removeElement($formulesOptionsInclus)) {
            // set the owning side to null (unless already changed)
            if ($formulesOptionsInclus->getFormule() === $this) {
                $formulesOptionsInclus->setFormule(null);
            }
        }

        return $this;
    }

    public function getFormulesRestriction(): ?FormulesRestriction
    {
        return $this->formulesRestriction;
    }

    public function setFormulesRestriction(?FormulesRestriction $formulesRestriction): static
    {
        // unset the owning side of the relation if necessary
        if ($formulesRestriction === null && $this->formulesRestriction !== null) {
            $this->formulesRestriction->setFormule(null);
        }

        // set the owning side of the relation if necessary
        if ($formulesRestriction !== null && $formulesRestriction->getFormule() !== $this) {
            $formulesRestriction->setFormule($this);
        }

        $this->formulesRestriction = $formulesRestriction;

        return $this;
    }

    public function getPos(): ?int
    {
        return $this->pos;
    }

    public function setPos(?int $pos): static
    {
        $this->pos = $pos;

        return $this;
    }
}
