<?php
namespace App\Entity;
use App\Repository\XmlApiRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Asserts;
use Doctrine\Common\Collections\Collection;
#[ORM\Entity(repositoryClass: XmlApiRepository::class)]
class XmlApi extends Product
{
const XMLAPI_DEFAULT_MARGIN = 10;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 128)]
private ?string $gdsCode = null;
#[ORM\Column(length: 32, nullable: true)]
private ?string $color = null;
#[ORM\Column]
private ?bool $payAtHotelAuthorized = null;
#[ORM\Column(nullable: true)]
#[Asserts\LessThanOrEqual(100, message: 'The value should be between 1 and 100!')]
private ?float $immediatePaymentPercent = null;
#[ORM\ManyToOne]
private ?CreditCard $creditCard = null;
#[ORM\Column]
private ?int $source = null;
#[ORM\Column]
private ?float $marginB2C = null;
#[ORM\Column]
private ?float $marginB2B = null;
#[ORM\OneToMany(mappedBy: 'xmlApi', targetEntity: CustomerXmlApi::class)]
private $customerXmlApis;
#[ORM\Column]
private ?bool $active = null;
#[ORM\Column(length: 45, nullable: true)]
private ?string $xmlApiType = null;
#[ORM\ManyToOne(inversedBy: 'b2cXmlApis')]
private ?MarkupStrategy $b2cMarkupStrategy = null;
#[ORM\ManyToOne(inversedBy: 'b2bXmlApis')]
private ?MarkupStrategy $b2bMarkupStrategy = null;
#[ORM\OneToMany(mappedBy: 'xmlApi', targetEntity: AirlineXmlApi::class, orphanRemoval: true)]
private Collection $airlineXmlApis;
public function __construct()
{
parent::__construct();
$this->customerXmlApis = new ArrayCollection();
$this->airlineXmlApis = new ArrayCollection();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getGdsCode(): ?string
{
return $this->gdsCode;
}
public function setGdsCode(string $gdsCode): self
{
$this->gdsCode = $gdsCode;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): self
{
$this->color = $color;
return $this;
}
public function isPayAtHotelAuthorized(): ?bool
{
return $this->payAtHotelAuthorized;
}
public function setPayAtHotelAuthorized(bool $payAtHotelAuthorized): self
{
$this->payAtHotelAuthorized = $payAtHotelAuthorized;
return $this;
}
public function getImmediatePaymentPercent(): ?float
{
return $this->immediatePaymentPercent;
}
public function setImmediatePaymentPercent(?float $immediatePaymentPercent): self
{
$this->immediatePaymentPercent = $immediatePaymentPercent;
return $this;
}
public function getCreditCard(): ?CreditCard
{
return $this->creditCard;
}
public function setCreditCard(?CreditCard $creditCard): self
{
$this->creditCard = $creditCard;
return $this;
}
public function getSource(): ?int
{
return $this->source;
}
public function setSource(int $source): self
{
$this->source = $source;
return $this;
}
public function __toString(): string
{
return $this->name ?? 'UNDEFINED';
// Todo - s'assurer que les xml-api ont des noms non vides
}
public function getmarginB2C(): ?float
{
return $this->marginB2C;
}
public function setmarginB2C(float $marginB2C): static
{
$this->marginB2C = $marginB2C;
return $this;
}
public function getmarginB2B(): ?float
{
return $this->marginB2B;
}
public function setmarginB2B(float $marginB2B): static
{
$this->marginB2B = $marginB2B;
return $this;
}
/**
* @return Collection<int, CustomerXmlApi>
*/
public function getCustomerXmlApis(): Collection
{
return $this->customerXmlApis;
}
public function addCustomerXmlApi(CustomerXmlApi $customerXmlApi): self
{
if (!$this->customerXmlApis->contains($customerXmlApi)) {
$this->customerXmlApis[] = $customerXmlApi;
$customerXmlApi->setXmlApi($this);
}
return $this;
}
public function removeCustomerXmlApis(CustomerXmlApi $customerXmlApis): self
{
if ($this->customerXmlApis->removeElement($customerXmlApis)) {
// set the owning side to null (unless already changed)
if ($customerXmlApis->getXmlApi() === $this) {
$customerXmlApis->setXmlApi(null);
}
}
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): static
{
$this->active = $active;
return $this;
}
public function getClass() : string {
return "XmlApi";
}
public function getIcon(): string
{
return match ($this->xmlApiType) {
"HOTEL" => "fas fa-hotel",
"TRANSFER" => "fas fa-car",
"FLIGHT" => "fas fa-plane",
default => "fe-rss",
};
}
public function getXmlApiType(): ?string
{
return $this->xmlApiType;
}
public function setXmlApiType(?string $xmlApiType): static
{
$this->xmlApiType = $xmlApiType;
return $this;
}
public function getB2cMarkupStrategy(): ?MarkupStrategy
{
return $this->b2cMarkupStrategy;
}
public function setB2cMarkupStrategy(?MarkupStrategy $b2cMarkupStrategy): static
{
$this->b2cMarkupStrategy = $b2cMarkupStrategy;
return $this;
}
public function getB2bMarkupStrategy(): ?MarkupStrategy
{
return $this->b2bMarkupStrategy;
}
public function setB2bMarkupStrategy(?MarkupStrategy $b2bMarkupStrategy): static
{
$this->b2bMarkupStrategy = $b2bMarkupStrategy;
return $this;
}
/**
* @return Collection<int, AirlineXmlApi>
*/
public function getAirlineXmlApis(): Collection
{
return $this->airlineXmlApis;
}
public function addAirlineXmlApi(AirlineXmlApi $airlineXmlApi): static
{
if (!$this->airlineXmlApis->contains($airlineXmlApi)) {
$this->airlineXmlApis->add($airlineXmlApi);
$airlineXmlApi->setXmlApi($this);
}
return $this;
}
public function removeAirlineXmlApi(AirlineXmlApi $airlineXmlApi): static
{
if ($this->airlineXmlApis->removeElement($airlineXmlApi)) {
// set the owning side to null (unless already changed)
if ($airlineXmlApi->getXmlApi() === $this) {
$airlineXmlApi->setXmlApi(null);
}
}
return $this;
}
}