<?php
namespace App\Entity\Retrocession;
use App\Entity\Adherent\Brand;
use App\Entity\Adherent\Magasin;
use App\Repository\Retrocession\AnnonceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
#[ORM\Table(name: 'retrocession_annonce')]
#[ORM\Entity(repositoryClass: AnnonceRepository::class)]
class Annonce implements \Stringable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\ManyToOne(targetEntity: Magasin::class, inversedBy: 'annonces')]
#[ORM\JoinColumn(name: 'magasin', referencedColumnName: 'k_adherent', nullable: false)]
private $magasin;
#[ORM\Column(type: 'string', length: 255)]
private $refAnnonce;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $refMonture;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $supplier;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $color;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $calibre;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $pont;
#[ORM\Column(type: 'integer', nullable: true)]
private $quantity;
#[ORM\Column(type: 'datetime_immutable')]
private $created_at;
#[ORM\Column(type: 'datetime_immutable')]
private $disable_at;
#[ORM\Column(type: 'datetime_immutable')]
private $end_at;
#[ORM\OneToMany(mappedBy: 'annonce', targetEntity: Photos::class, cascade: ['persist', 'remove'])]
private $photos;
#[ORM\ManyToOne(targetEntity: Brand::class, inversedBy: 'annonces')]
#[ORM\JoinColumn(nullable: true)]
private $brand;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $otherBrand;
#[ORM\Column(type: "string", nullable: false)]
private $region = null;
#[ORM\Column(type: "string", nullable: false)]
private $pays = "FR";
#[ORM\Column]
private ?bool $deleted = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $type = null;
#[ORM\Column(name: 'brouillon', type: 'boolean')]
private bool $brouillon = false;
#[ORM\Column(name: 'reactivate', type: 'boolean')]
private bool $reactivate = false;
public function __construct()
{
$this->created_at = new \DateTimeImmutable("now");
$interval_oneMonth = new \DateInterval('P1M');
$interval_twoMonth = new \DateInterval('P2M');
$this->disable_at = $this->created_at->add($interval_oneMonth);
// $this->end_at = $this->created_at->add($interval_twoMonth);
$this->end_at = $this->created_at->add($interval_oneMonth);
$this->deleted = 0;
$this->photos = new ArrayCollection();
$this->refAnnonce = 'A'.sprintf("%06d", random_int(1, 999999));
}
public function __toString(): string
{
return (string) $this->getRefAnnonce();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
public function setId(mixed $id): void
{
$this->id = $id;
}
/**
* @return mixed
*/
public function getMagasin()
{
return $this->magasin;
}
public function setMagasin(mixed $magasin): void
{
$this->magasin = $magasin;
}
/**
* @return mixed
*/
public function getRefAnnonce()
{
return $this->refAnnonce;
}
public function setRefAnnonce(mixed $refAnnonce): void
{
$this->refAnnonce = $refAnnonce;
}
/**
* @return mixed
*/
public function getRefMonture()
{
return $this->refMonture;
}
public function setRefMonture(mixed $refMonture): void
{
$this->refMonture = $refMonture;
}
/**
* @return mixed
*/
public function getSupplier()
{
return $this->supplier;
}
public function setSupplier(mixed $supplier): void
{
$this->supplier = $supplier;
}
/**
* @return mixed
*/
public function getColor()
{
return $this->color;
}
public function setColor(mixed $color): void
{
$this->color = $color;
}
/**
* @return mixed
*/
public function getCalibre()
{
return $this->calibre;
}
public function setCalibre(mixed $calibre): void
{
$this->calibre = $calibre;
}
/**
* @return mixed
*/
public function getPont()
{
return $this->pont;
}
public function setPont(mixed $pont): void
{
$this->pont = $pont;
}
/**
* @return mixed
*/
public function getQuantity()
{
return $this->quantity;
}
public function setQuantity(mixed $quantity): void
{
$this->quantity = $quantity;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): void
{
$this->created_at = $created_at;
}
public function getDisableAt(): \DateTimeImmutable
{
return $this->disable_at;
}
public function setDisableAt(\DateTimeImmutable $disable_at): void
{
$this->disable_at = $disable_at;
}
public function getEndAt(): \DateTimeImmutable
{
return $this->end_at;
}
public function setEndAt(\DateTimeImmutable $end_at): void
{
$this->end_at = $end_at;
}
/**
* @return Collection<int, Photos>
*/
public function getPhotos(): Collection
{
return $this->photos;
}
public function addPhoto(Photos $photo): self
{
if (!$this->photos->contains($photo)) {
$this->photos[] = $photo;
$photo->setAnnonce($this);
}
return $this;
}
public function removePhoto(Photos $photo): self
{
if ($this->photos->removeElement($photo)) {
// set the owning side to null (unless already changed)
if ($photo->getAnnonce() === $this) {
$photo->setAnnonce(null);
}
}
return $this;
}
public function getBrand(): ?Brand
{
return $this->brand;
}
public function setBrand(?Brand $brand): self
{
$this->brand = $brand;
return $this;
}
public function getRegion()
{
return $this->region;
}
public function setRegion($region): self
{
$this->region = $region;
return $this;
}
/**
* @return string
*/
public function getPays(): string
{
return $this->pays;
}
/**
* @param string $pays
*/
public function setPays(string $pays): void
{
$this->pays = $pays;
}
public function isDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(bool $deleted): self
{
$this->deleted = $deleted;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
/**
* @return mixed
*/
public function getOtherBrand()
{
return $this->otherBrand;
}
/**
* @param mixed $otherBrand
*/
public function setOtherBrand($otherBrand): void
{
$this->otherBrand = $otherBrand;
}
// #[Assert\Callback]
// public function validate(ExecutionContextInterface $context, $payload)
// {
//
// dd($this);
// if (null === $this->getBrand() && null === $this->getOtherBrand()){
// $context->buildViolation('veuillez.renseigner.une.marque')
// ->atPath('brand')
// ->addViolation();
// }
// }
public function isBrouillon(): ?bool
{
return $this->brouillon;
}
public function setBrouillon(bool $brouillon): self
{
$this->brouillon = $brouillon;
return $this;
}
public function isReactivate(): ?bool
{
return $this->reactivate;
}
public function setReactivate(bool $reactivate): self
{
$this->reactivate = $reactivate;
return $this;
}
}