<?php
namespace App\Entity;
use App\Repository\MarkupStrategyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MarkupStrategyRepository::class)]
class MarkupStrategy
{
public const PRODUCT_HOTEL = 1;
public const PRODUCT_TRANSFER = 2;
public const PRODUCT_FLIGHT = 3;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'markupStrategy', targetEntity: MarkupRule::class)]
private Collection $rules;
#[ORM\OneToMany(mappedBy: 'markupStrategy', targetEntity: CustomerXmlApi::class)]
private Collection $customerXmlApis;
#[ORM\Column(type: 'integer', nullable: false)]
private ?int $product = null;
#[ORM\OneToMany(mappedBy: 'b2cMarkupStrategy', targetEntity: XmlApi::class)]
private Collection $b2cXmlApis;
#[ORM\OneToMany(mappedBy: 'b2bMarkupStrategy', targetEntity: XmlApi::class)]
private Collection $b2bXmlApis;
public function __construct()
{
$this->rules = new ArrayCollection();
$this->customerXmlApis = new ArrayCollection();
$this->b2cXmlApis = new ArrayCollection();
$this->b2bXmlApis = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getProduct(): ?int
{
return $this->product;
}
public function setProduct(?int $product): static
{
$this->product = $product;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, MarkupRule>
*/
public function getRules(): Collection
{
return $this->rules;
}
public function addRule(MarkupRule $rule): static
{
if (!$this->rules->contains($rule)) {
$this->rules->add($rule);
$rule->setMarkupStrategy($this);
}
return $this;
}
public function removeRule(MarkupRule $rule): static
{
if ($this->rules->removeElement($rule)) {
// set the owning side to null (unless already changed)
if ($rule->getMarkupStrategy() === $this) {
$rule->setMarkupStrategy(null);
}
}
return $this;
}
/**
* @return Collection<int, CustomerXmlApi>
*/
public function getCustomerXmlApis(): Collection
{
return $this->customerXmlApis;
}
public function addCustomerXmlApi(CustomerXmlApi $customerXmlApi): static
{
if (!$this->customerXmlApis->contains($customerXmlApi)) {
$this->customerXmlApis->add($customerXmlApi);
$customerXmlApi->setMarkupStrategy($this);
}
return $this;
}
public function removeCustomerXmlApi(CustomerXmlApi $customerXmlApi): static
{
if ($this->customerXmlApis->removeElement($customerXmlApi)) {
// set the owning side to null (unless already changed)
if ($customerXmlApi->getMarkupStrategy() === $this) {
$customerXmlApi->setMarkupStrategy(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->name ?? ' ';
}
public static function getProductStrategies(): array
{
return [
'Hotel' => self::PRODUCT_HOTEL,
'Transfer' => self::PRODUCT_TRANSFER,
'Flight' => self::PRODUCT_FLIGHT,
];
}
public function getProductName(): string
{
$productNames = [
self::PRODUCT_HOTEL => 'Hotel',
self::PRODUCT_TRANSFER => 'Transfer',
self::PRODUCT_FLIGHT => 'Flight',
];
return $productNames[$this->product] ?? 'Unknown';
}
/**
* @return Collection<int, XmlApi>
*/
public function getB2cXmlApis(): Collection
{
return $this->b2cXmlApis;
}
public function addB2cXmlApi(XmlApi $b2cXmlApi): static
{
if (!$this->b2cXmlApis->contains($b2cXmlApi)) {
$this->b2cXmlApis->add($b2cXmlApi);
$b2cXmlApi->setB2cMarkupStrategy($this);
}
return $this;
}
public function removeB2cXmlApi(XmlApi $b2cXmlApi): static
{
if ($this->b2cXmlApis->removeElement($b2cXmlApi)) {
// set the owning side to null (unless already changed)
if ($b2cXmlApi->getB2cMarkupStrategy() === $this) {
$b2cXmlApi->setB2cMarkupStrategy(null);
}
}
return $this;
}
/**
* @return Collection<int, XmlApi>
*/
public function getB2bXmlApis(): Collection
{
return $this->b2bXmlApis;
}
public function addB2bXmlApi(XmlApi $b2bXmlApi): static
{
if (!$this->b2bXmlApis->contains($b2bXmlApi)) {
$this->b2bXmlApis->add($b2bXmlApi);
$b2bXmlApi->setB2bMarkupStrategy($this);
}
return $this;
}
public function removeB2bXmlApi(XmlApi $b2bXmlApi): static
{
if ($this->b2bXmlApis->removeElement($b2bXmlApi)) {
// set the owning side to null (unless already changed)
if ($b2bXmlApi->getB2bMarkupStrategy() === $this) {
$b2bXmlApi->setB2bMarkupStrategy(null);
}
}
return $this;
}
}