<?php
namespace App\Flexy\ShopBundle\Entity\Customer;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\User;
use App\Flexy\ShopBundle\Entity\Order\Order;
use App\Flexy\ShopBundle\Entity\Product\Comment;
use App\Flexy\ShopBundle\Entity\Product\Product;
use App\Flexy\ShopBundle\Repository\Customer\CustomerRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use \App\Flexy\ShopBundle\Entity\Order\ReturnOrder;
/**
* @ORM\Entity(repositoryClass=CustomerRepository::class)
*/
#[ApiResource]
class Customer
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $email;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $address;
/**
* @ORM\Column(type="string", length=255)
*
*/
private $phone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $companyName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $addressIndication;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $country;
/**
* @ORM\Column(type="string", length=255, nullable="true")
*/
private $postCode;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="customer", orphanRemoval=true,cascade={"persist"})
*/
private $orders;
/**
* @ORM\ManyToOne(targetEntity=CustomerGroup::class, inversedBy="customers")
*/
private $customerGroup;
/**
* @ORM\OneToOne(targetEntity=User::class, cascade={"persist", "remove"})
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="customer")
*/
private $comments;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $gender;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $dateOfBirth;
/**
* @ORM\OneToMany(targetEntity=CustomerAddress::class, mappedBy="customer",cascade={"persist"})
*/
private $customerAddresses;
/**
* @ORM\OneToMany(targetEntity=Product::class, mappedBy="customer")
*/
private $products;
/**
* @ORM\OneToMany(targetEntity=ReturnOrder::class, mappedBy="customer")
*/
private $repayment;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->customerAddresses = new ArrayCollection();
$this->products = new ArrayCollection();
$this->repayment = new ArrayCollection();
}
public function __toString()
{
return $this->firstName." ".$this->lastName;
}
public function getId(): ?int
{
return $this->id;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(?string $companyName): self
{
$this->companyName = $companyName;
return $this;
}
public function getAddressIndication(): ?string
{
return $this->addressIndication;
}
public function setAddressIndication(?string $addressIndication): self
{
$this->addressIndication = $addressIndication;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
public function getPostCode(): ?string
{
return $this->postCode;
}
public function setPostCode(string $postCode): self
{
$this->postCode = $postCode;
return $this;
}
/**
* @return Collection|Order[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setCustomer($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getCustomer() === $this) {
$order->setCustomer(null);
}
}
return $this;
}
public function getCustomerGroup(): ?CustomerGroup
{
return $this->customerGroup;
}
public function setCustomerGroup(?CustomerGroup $customerGroup): self
{
$this->customerGroup = $customerGroup;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setCustomer($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getCustomer() === $this) {
$comment->setCustomer(null);
}
}
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(?string $gender): self
{
$this->gender = $gender;
return $this;
}
public function getDateOfBirth(): ?\DateTimeInterface
{
return $this->dateOfBirth;
}
public function setDateOfBirth(?\DateTimeInterface $dateOfBirth): self
{
$this->dateOfBirth = $dateOfBirth;
return $this;
}
/**
* @return Collection<int, CustomerAddress>
*/
public function getCustomerAddresses(): Collection
{
return $this->customerAddresses;
}
public function addCustomerAddress(CustomerAddress $customerAddress): self
{
if (!$this->customerAddresses->contains($customerAddress)) {
$this->customerAddresses[] = $customerAddress;
$customerAddress->setCustomer($this);
}
return $this;
}
public function removeCustomerAddress(CustomerAddress $customerAddress): self
{
if ($this->customerAddresses->removeElement($customerAddress)) {
// set the owning side to null (unless already changed)
if ($customerAddress->getCustomer() === $this) {
$customerAddress->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setCustomer($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getCustomer() === $this) {
$product->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection<int, ReturnOrder>
*/
public function getRepayment(): Collection
{
return $this->repayment;
}
public function addRepayment(ReturnOrder $repayment): self
{
if (!$this->repayment->contains($repayment)) {
$this->repayment[] = $repayment;
$repayment->setCustomer($this);
}
return $this;
}
public function removeRepayment(ReturnOrder $repayment): self
{
if ($this->repayment->removeElement($repayment)) {
// set the owning side to null (unless already changed)
if ($repayment->getCustomer() === $this) {
$repayment->setCustomer(null);
}
}
return $this;
}
}