<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\AccountAddressRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
#[ORM\Entity(repositoryClass: AccountAddressRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['account_address:read']],
denormalizationContext: ['groups' => ['account_address:write']],
order: ['id' => 'DESC'],
)]
#[ApiFilter(SearchFilter::class, properties: [
'name' => 'ipartial',
'account' => 'exact',
])]
class AccountAddress
{
#[Groups(['account_address:read', 'account_address:write', 'account:read', 'order:read', 'pre_order:read','agreements:read'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Groups(['account_address:read', 'account_address:write', 'account:read', 'order:read', 'pre_order:read','agreements:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['account_address:read', 'account_address:write', 'account:read', 'order:read', 'pre_order:read','agreements:read'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['account_address:read', 'account_address:write'])]
#[ORM\ManyToOne(inversedBy: 'accountAddresses')]
private ?Accounts $account = null;
#[Groups(['account_address:read', 'account_address:write', 'account:read', 'order:read', 'pre_order:read','agreements:read'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $code1c = null;
#[Groups(['account_address:read', 'account_address:write'])]
#[ORM\OneToMany(mappedBy: 'address', targetEntity: Orders::class)]
private Collection $orders;
#[Groups(['account_address:read', 'account_address:write'])]
#[ORM\OneToMany(mappedBy: 'address', targetEntity: PreOrder::class)]
private Collection $preOrders;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->preOrders = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getAccount(): ?Accounts
{
return $this->account;
}
public function setAccount(?Accounts $account): self
{
$this->account = $account;
return $this;
}
public function getCode1c(): ?string
{
return $this->code1c;
}
public function setCode1c(?string $code1c): self
{
$this->code1c = $code1c;
return $this;
}
/**
* @return Collection<int, Orders>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Orders $order): self
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setAddress($this);
}
return $this;
}
public function removeOrder(Orders $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getAddress() === $this) {
$order->setAddress(null);
}
}
return $this;
}
/**
* @return Collection<int, PreOrder>
*/
public function getPreOrders(): Collection
{
return $this->preOrders;
}
public function addPreOrder(PreOrder $preOrder): self
{
if (!$this->preOrders->contains($preOrder)) {
$this->preOrders->add($preOrder);
$preOrder->setAddress($this);
}
return $this;
}
public function removePreOrder(PreOrder $preOrder): self
{
if ($this->preOrders->removeElement($preOrder)) {
// set the owning side to null (unless already changed)
if ($preOrder->getAddress() === $this) {
$preOrder->setAddress(null);
}
}
return $this;
}
}