<?php
namespace App\Entity\Segmentation;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Operation\Coupon;
use App\Repository\DepartmentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
use Ramsey\Uuid\Doctrine\UuidGenerator;
/**
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={
* "Department:output",
* "Department:io",
* }},
* "denormalization_context"={"groups"={
* "Department:input",
* "Department:io",
* }}
* },
* collectionOperations={
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_USER')",
* },
* },
* itemOperations={
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_USER')",
* },
* }
* )
* @ORM\Entity(repositoryClass=DepartmentRepository::class)
* @UniqueEntity("code")
*/
class Department
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @SerializedName("id")
* @ApiProperty(identifier=true)
* @Assert\Uuid()
* @Groups({
* "Department:output",
* "get_all_public_coupons",
* })
*
*/
private string $id;
/**
* @ORM\Column(type="string", length=3)
* @SerializedName("code")
* @Groups({
* "Department:output",
* "get_all_public_coupons",
* })
*/
private ?string $code;
/**
* @var Collection
*
* @ORM\ManyToMany(targetEntity="App\Entity\Operation\Coupon", mappedBy="departments")
* @SerializedName("coupons")
* @Groups({
* "Department:output",
* })
*/
private Collection $coupons;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\User\Address\Home", mappedBy="department", cascade={"persist"})
*/
private $address;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\User\Address\Delivery", mappedBy="department", cascade={"persist"})
*/
private $delivery;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\User\Address\Order", mappedBy="department", cascade={"persist"})
*/
private $order;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity=Region::class, inversedBy="departments", fetch="EAGER")
* @Groups({
* "Department:output",
* })
*/
private $region;
public function __construct()
{
$this->coupons = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
/**
* @return Collection
*/
public function getCoupons(): Collection
{
return $this->coupons;
}
public function addCoupon(Coupon $coupon): Department
{
if ($this->coupons->contains($coupon)) {
return $this;
}
$this->coupons[] = $coupon;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getRegion(): ?Region
{
return $this->region;
}
public function setRegion(?Region $region): self
{
$this->region = $region;
return $this;
}
}