<?php
namespace App\Entity\Adherent;
use App\Repository\Adherent\MagasinCoordonneesRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'magasin_coordonnees')]
#[ORM\Entity(repositoryClass: MagasinCoordonneesRepository::class)]
#[ORM\HasLifecycleCallbacks]
class MagasinCoordonnees
{
#[ORM\Id]
#[ORM\Column(type: 'string', length: 255)]
private string $K_ADHERENT;
#[ORM\Id]
#[ORM\Column(type: 'string', length: 255)]
private string $TYPE;
#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
private string $LIB;
#[ORM\Column(type: 'integer')]
private int|null $ID_ANNUAIRE_PROGRESS;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $VOIE_NUM;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $VOIE_CPLT;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $VOIE_TYPE;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $VOIE_LIB;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $VOIE_LIB2;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $BAT;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $ENTREE;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $ETAGE;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $APPART;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $BP;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $CEDEX_CP;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $CEDEX_NUM;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $LAT;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private string|null $LON;
#[ORM\Column(type: 'string', length: 255)]
private string $K_CP;
#[ORM\Column(type: 'string', length: 255)]
private string $K_VILLE;
#[ORM\Column(type: 'string', length: 255)]
private string $K_PAYS;
#[ORM\Column(type: 'datetime_immutable')]
private DateTimeImmutable $createdAt;
#[ORM\ManyToOne(targetEntity: Magasin::class, inversedBy: 'magasinCoordonnees')]
#[ORM\JoinColumn(name: 'magasin', referencedColumnName: 'k_adherent')]
private Magasin $magasin;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private DateTimeImmutable|null $updatedAt;
public function __construct()
{
$this->createdAt = new DateTimeImmutable("now");
$this->updatedAt = new DateTimeImmutable("now");
}
public function __toString(): string
{
$parts = [];
// Partie principale de l'adresse
if (!empty($this->VOIE_NUM)) {
$parts[] = $this->VOIE_NUM;
}
if (!empty($this->VOIE_CPLT)) {
$parts[] = $this->VOIE_CPLT;
}
if (!empty($this->VOIE_TYPE)) {
$parts[] = $this->VOIE_TYPE;
}
if (!empty($this->VOIE_LIB)) {
$parts[] = $this->VOIE_LIB;
}
if (!empty($this->VOIE_LIB2)) {
$parts[] = $this->VOIE_LIB2;
}
// Compléments (bâtiment, étage, appartement)
$complements = [];
if (!empty($this->BAT)) {
$complements[] = "Bât. " . $this->BAT;
}
if (!empty($this->ENTREE)) {
$complements[] = "Entrée " . $this->ENTREE;
}
if (!empty($this->ETAGE)) {
$complements[] = "Étage " . $this->ETAGE;
}
if (!empty($this->APPART)) {
$complements[] = "App. " . $this->APPART;
}
if (!empty($complements)) {
$parts[] = implode(', ', $complements);
}
// BP et CEDEX
if (!empty($this->BP)) {
$parts[] = "BP " . $this->BP;
}
if (!empty($this->CEDEX_CP) && !empty($this->CEDEX_NUM)) {
$parts[] = "CEDEX " . $this->CEDEX_CP . " " . $this->CEDEX_NUM;
}
// Code postal, ville et pays
if (!empty($this->K_CP)) {
$parts[] = $this->K_CP;
}
if (!empty($this->K_VILLE)) {
$parts[] = $this->K_VILLE;
}
if (!empty($this->K_PAYS)) {
$parts[] = $this->K_PAYS;
}
return implode(' ', $parts);
}
#[ORM\PreUpdate]
public function onPreUpdateEntity(): void
{
$this->updatedAt = new DateTimeImmutable("now");
}
public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return string
*/
public function getKADHERENT(): string
{
return $this->K_ADHERENT;
}
public function setKADHERENT(mixed $K_ADHERENT): void
{
$this->K_ADHERENT = $K_ADHERENT;
}
/**
* @return string
*/
public function getTYPE(): string
{
return $this->TYPE;
}
public function setTYPE(mixed $TYPE): void
{
$this->TYPE = $TYPE;
}
/**
* @return string
*/
public function getLIB(): string
{
return $this->LIB;
}
public function setLIB(mixed $LIB): void
{
$this->LIB = $LIB;
}
/**
* @return int|null
*/
public function getIDANNUAIREPROGRESS(): ?int
{
return $this->ID_ANNUAIRE_PROGRESS;
}
public function setIDANNUAIREPROGRESS(int $ID_ANNUAIRE_PROGRESS): void
{
$this->ID_ANNUAIRE_PROGRESS = $ID_ANNUAIRE_PROGRESS;
}
/**
* @return string|null
*/
public function getVOIENUM(): ?string
{
return $this->VOIE_NUM;
}
public function setVOIENUM(mixed $VOIE_NUM): void
{
$this->VOIE_NUM = $VOIE_NUM;
}
/**
* @return string|null
*/
public function getVOIECPLT(): ?string
{
return $this->VOIE_CPLT;
}
public function setVOIECPLT(mixed $VOIE_CPLT): void
{
$this->VOIE_CPLT = $VOIE_CPLT;
}
/**
* @return string|null
*/
public function getVOIETYPE(): ?string
{
return $this->VOIE_TYPE;
}
public function setVOIETYPE(mixed $VOIE_TYPE): void
{
$this->VOIE_TYPE = $VOIE_TYPE;
}
/**
* @return string|null
*/
public function getVOIELIB(): ?string
{
return $this->VOIE_LIB;
}
public function setVOIELIB(mixed $VOIE_LIB): void
{
$this->VOIE_LIB = $VOIE_LIB;
}
/**
* @return string|null
*/
public function getVOIELIB2(): ?string
{
return $this->VOIE_LIB2;
}
public function setVOIELIB2(mixed $VOIE_LIB2): void
{
$this->VOIE_LIB2 = $VOIE_LIB2;
}
public function getBAT(): ?string
{
return $this->BAT;
}
public function setBAT(mixed $BAT): void
{
$this->BAT = $BAT;
}
public function getENTREE(): ?string
{
return $this->ENTREE;
}
public function setENTREE(mixed $ENTREE): void
{
$this->ENTREE = $ENTREE;
}
public function getETAGE(): ?string
{
return $this->ETAGE;
}
public function setETAGE(mixed $ETAGE): void
{
$this->ETAGE = $ETAGE;
}
public function getAPPART(): ?string
{
return $this->APPART;
}
public function setAPPART(mixed $APPART): void
{
$this->APPART = $APPART;
}
public function getBP(): ?string
{
return $this->BP;
}
public function setBP(mixed $BP): void
{
$this->BP = $BP;
}
public function getCEDEXCP(): ?string
{
return $this->CEDEX_CP;
}
public function setCEDEXCP(mixed $CEDEX_CP): void
{
$this->CEDEX_CP = $CEDEX_CP;
}
public function getCEDEXNUM(): ?string
{
return $this->CEDEX_NUM;
}
public function setCEDEXNUM(mixed $CEDEX_NUM): void
{
$this->CEDEX_NUM = $CEDEX_NUM;
}
public function getLAT(): ?string
{
return $this->LAT;
}
public function setLAT(mixed $LAT): void
{
$this->LAT = $LAT;
}
public function getLON(): ?string
{
return $this->LON;
}
public function setLON(mixed $LON): void
{
$this->LON = $LON;
}
public function getKCP(): ?string
{
return $this->K_CP;
}
public function setKCP(mixed $K_CP): void
{
$this->K_CP = $K_CP;
}
public function getKVILLE(): ?string
{
return $this->K_VILLE;
}
public function setKVILLE(mixed $K_VILLE): void
{
$this->K_VILLE = $K_VILLE;
}
public function getKPAYS(): string
{
return $this->K_PAYS;
}
public function setKPAYS(mixed $K_PAYS): void
{
$this->K_PAYS = $K_PAYS;
}
public function getMagasin(): ?Magasin
{
return $this->magasin;
}
public function setMagasin(?Magasin $magasin): self
{
$this->magasin = $magasin;
return $this;
}
public function getUpdatedAt(): ?DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(DateTimeImmutable $updatedAt): void
{
$this->updatedAt = $updatedAt;
}
public function toArray(): array
{
return [
'k_adherent' => $this->K_ADHERENT,
'type' => $this->TYPE,
'id_annuaire_progress' => $this->ID_ANNUAIRE_PROGRESS,
'magasin' => $this->magasin->getKAdherent(),
'lib' => $this->LIB,
'voie_num' => $this->VOIE_NUM,
'voie_cplt' => $this->VOIE_CPLT,
'voie_type' => $this->VOIE_TYPE,
'voie_lib' => $this->VOIE_LIB,
'voie_lib2' => $this->VOIE_LIB2,
'bat' => $this->BAT,
'entree' => $this->ENTREE,
'etage' => $this->ETAGE,
'appart' => $this->APPART,
'bp' => $this->BP,
'cedex_cp' => $this->CEDEX_CP,
'cedex_num' => $this->CEDEX_NUM,
'lat' => $this->LAT,
'lon' => $this->LON,
'k_cp' => $this->K_CP,
'k_ville' => $this->K_VILLE,
'k_pays' => $this->K_PAYS
];
}
public function updateForm(MagasinCoordonnees $magasinCoordonnee): self
{
$this->setLIB($magasinCoordonnee->getLIB());
$this->setVOIENUM($magasinCoordonnee->getVOIENUM());
$this->setVOIECPLT($magasinCoordonnee->getVOIECPLT());
$this->setVOIELIB2($magasinCoordonnee->getVOIELIB2());
$this->setVOIETYPE($magasinCoordonnee->getVOIETYPE());
$this->setVOIELIB($magasinCoordonnee->getVOIELIB());
$this->setBAT($magasinCoordonnee->getBAT());
$this->setENTREE($magasinCoordonnee->getENTREE());
$this->setETAGE($magasinCoordonnee->getETAGE());
$this->setAPPART($magasinCoordonnee->getAPPART());
$this->setBP($magasinCoordonnee->getBP());
$this->setCEDEXCP($magasinCoordonnee->getCEDEXCP());
$this->setCEDEXNUM($magasinCoordonnee->getCEDEXNUM());
$this->setKCP($magasinCoordonnee->getKCP());
$this->setKVILLE($magasinCoordonnee->getKVILLE());
return $this;
}
}