<?php
namespace Evo\Infrastructure\MappingORM;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Store entity.
*
* @ApiResource(attributes={
* "normalization_context"={"groups"={"read_store"}},
* "denormalization_context"={"groups"={"write_store"}}
* },
* cacheHeaders={"max_age"=86400, "shared_max_age"=86400},
* itemOperations={"get", "put"})
* @ApiFilter(SearchFilter::class, properties={
* "postalAddress.postalCode": "exact",
* "status":"exact",
* "sector.id": "exact",
* "sector": "exact",
* "sector.name": "exact",
* "name": "start"
* })
* @ApiFilter(PropertyFilter::class)
* @ORM\Entity
* @ORM\Table(name="store")
* @ORM\Entity(repositoryClass="App\Repository\StoreRepository")
*/
class Store
{
/**
* @var int The entity Id
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"read_store", "read_organization", "read_discount", "read_pack", "admin_orga_list", "read_discount_for_select", "read_product_with_store"})
*/
private int $id;
/**
* @var string The store name
*
* @Groups({"read_store", "write_store", "read_user", "read_organization", "write_organization", "read_discount", "read_pack", "admin_orga_list", "read_discount_for_select", "read_product_with_store"})
* @ORM\Column(type="string")
*/
private ?string $name = null;
/**
* @Groups({"read_store", "write_store", "read_user", "read_organization", "write_organization", "admin:orga:select",})
* @ORM\OneToOne(targetEntity="PostalAddress", cascade={"persist"})
* @ORM\JoinColumn(name="postal_address_id", referencedColumnName="id")
*/
private ?PostalAddress $postalAddress = null;
/**
* @var array The store opening hours
*
* @Groups({"read_store", "write_store", "read_organization", "write_organization"})
* @ORM\Column(type="array")
*/
private $openingHours;
/**
* @var array The store currencies accepted
*
* @Groups({"read_store", "write_store", "read_organization", "write_organization"})
* @ORM\Column(type="array")
*/
private $currenciesAccepted;
/**
* @var string The store type of the accepted payment
*
* @Groups({"read_store", "write_store", "read_organization", "write_organization"})
* @ORM\Column(type="string")
*/
private ?string $paymentAcceptedType = null;
/**
* @var array The store price range
*
* @Groups({"read_store", "write_store", "read_organization", "write_organization"})
* @ORM\Column(type="array")
*/
private $priceRange;
/**
* @var int The store aggregate rating
*
* @Groups({"read_store", "write_store", "read_organization", "write_organization"})
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $aggregateRating = null;
/**
* @Groups({"read_store", "read_organization"})
* @ORM\Column(name="created_at", type="datetime")
*/
private ?\DateTimeInterface $createdAt;
/**
* @ORM\OneToMany(targetEntity="Evo\Infrastructure\MappingORM\Organization", mappedBy="store")
*/
private ?Collection $organizations;
/**
* @Groups({"read_store", "read_organization"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $prefectoralApprovalNumber = null;
/**
* @Groups({"read_store", "read_organization"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $status = null;
/**
* @Groups({"read_store", "read_organization"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $cedex = null;
/**
* @ORM\ManyToMany(targetEntity=DiscountCode::class, mappedBy="store")
*/
private ?Collection $discountCodes;
/**
* @Groups({"read_store", "read_organization"})
* @ORM\ManyToOne(targetEntity=Sector::class, inversedBy="stores")
*/
private ?Sector $sector = null;
/**
* @ORM\OneToMany(targetEntity=BAL::class, mappedBy="store", orphanRemoval=true)
*/
private Collection $bal;
/**
* @ORM\Column(type="boolean")
*/
private bool $isExportableIbml = false;
public function __construct()
{
$this->organizations = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->discountCodes = new ArrayCollection();
$this->bal = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
public function setName(string $name): Store
{
$this->name = $name;
return $this;
}
/**
* @return PostalAddress
*/
public function getPostalAddress()
{
return $this->postalAddress;
}
public function getStandardizedAddress(): ?string
{
return $this->postalAddress ? ($this->postalAddress->getStandardizedAddress() ?: $this->postalAddress->getStreetAddress()) : null;
}
public function setPostalAddress(PostalAddress $postalAddress): Store
{
$this->postalAddress = $postalAddress;
return $this;
}
/**
* @return array
*/
public function getOpeningHours()
{
return $this->openingHours;
}
public function setOpeningHours(array $openingHours): Store
{
$this->openingHours = $openingHours;
return $this;
}
/**
* @return array
*/
public function getCurrenciesAccepted()
{
return $this->currenciesAccepted;
}
public function setCurrenciesAccepted(array $currenciesAccepted): Store
{
$this->currenciesAccepted = $currenciesAccepted;
return $this;
}
/**
* @return string
*/
public function getPaymentAcceptedType()
{
return $this->paymentAcceptedType;
}
public function setPaymentAcceptedType(string $paymentAcceptedType): Store
{
$this->paymentAcceptedType = $paymentAcceptedType;
return $this;
}
/**
* @return array
*/
public function getPriceRange()
{
return $this->priceRange;
}
public function setPriceRange(array $priceRange): Store
{
$this->priceRange = $priceRange;
return $this;
}
/**
* @return int
*/
public function getAggregateRating()
{
return $this->aggregateRating;
}
public function setAggregateRating(int $aggregateRating): Store
{
$this->aggregateRating = $aggregateRating;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime|\DateTimeImmutable $createdAt
*/
public function setCreatedAt(?\DateTimeInterface $createdAt): Store
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection|Organization[]
*/
public function getOrganizations(): Collection
{
return $this->organizations;
}
public function addOrganization(Organization $organization): self
{
if (!$this->organizations->contains($organization)) {
$this->organizations[] = $organization;
$organization->setStore($this);
}
return $this;
}
public function removeOrganization(Organization $organization): self
{
if ($this->organizations->contains($organization)) {
$this->organizations->removeElement($organization);
// set the owning side to null (unless already changed)
if ($organization->getStore() === $this) {
$organization->setStore(null);
}
}
return $this;
}
public function getPrefectoralApprovalNumber(): ?string
{
return $this->prefectoralApprovalNumber;
}
public function setPrefectoralApprovalNumber(?string $prefectoralApprovalNumber): self
{
$this->prefectoralApprovalNumber = $prefectoralApprovalNumber;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function getCedex(): ?string
{
return $this->cedex;
}
public function setCedex(?string $cedex): self
{
$this->cedex = $cedex;
return $this;
}
/**
* @return Collection|DiscountCode[]
*/
public function getDiscountCodes(): Collection
{
return $this->discountCodes;
}
public function addDiscountCode(DiscountCode $discountCode): self
{
if (!$this->discountCodes->contains($discountCode)) {
$this->discountCodes[] = $discountCode;
$discountCode->addStore($this);
}
return $this;
}
public function removeDiscountCode(DiscountCode $discountCode): self
{
if ($this->discountCodes->removeElement($discountCode)) {
$discountCode->removeStore($this);
}
return $this;
}
public function getSector(): ?Sector
{
return $this->sector;
}
public function setSector(?Sector $sector): self
{
$this->sector = $sector;
return $this;
}
/**
* @return Collection|BAL[]
*/
public function getBal(): Collection
{
return $this->bal;
}
public function addBal(BAL $bal): self
{
if (!$this->bal->contains($bal)) {
$this->bal[] = $bal;
$bal->setStore($this);
}
return $this;
}
public function removeBal(BAL $bal): self
{
if ($this->bal->removeElement($bal)) {
// set the owning side to null (unless already changed)
if ($bal->getStore() === $this) {
$bal->setStore(null);
}
}
return $this;
}
public function getIsExportableIbml(): bool
{
return $this->isExportableIbml;
}
public function setIsExportableIbml(bool $isExportableIbml): self
{
$this->isExportableIbml = $isExportableIbml;
return $this;
}
}