<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\FactoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use ApiPlatform\Core\Annotation\ApiProperty;
#[ORM\Entity(repositoryClass: FactoryRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['factory:read']],
denormalizationContext: ['groups' => ['factory:write']],
order: ['id' => 'DESC'],
)]
#[ApiFilter(SearchFilter::class, properties: [
'name' => 'ipartial',
'code1c' => 'exact',
])]
class Factory
{
#[Groups(['factory:read', 'factory:write', 'enginneer:read', 'job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write' , 'account_worker:read' ])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Groups(['factory:read', 'factory:write', 'enginneer:read', 'job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write' , 'account_worker:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['factory:read', 'factory:write', 'enginneer:read', 'job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write' , 'account_worker:read' ])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['factory:read', 'factory:write', 'enginneer:read', 'job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write' , 'account_worker:read' ])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $code1c = null;
#[Groups(['factory:read', 'factory:write', 'job:read', 'job:write', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write' ])]
#[ORM\OneToMany(mappedBy: 'factory', targetEntity: Engineer::class)]
private Collection $engineers;
#[Groups(['factory:read', 'factory:write', 'enginneer:read', 'worker:read', 'worker:write', 'account_worker:read', 'account:read', 'read', 'account:write' ])]
#[ORM\OneToMany(mappedBy: 'factory', targetEntity: Jobs::class)]
private Collection $jobs;
public function __construct()
{
$this->engineers = new ArrayCollection();
$this->jobs = 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 getCode1c(): ?string
{
return $this->code1c;
}
public function setCode1c(?string $code1c): self
{
$this->code1c = $code1c;
return $this;
}
/**
* @return Collection<int, Engineer>
*/
public function getEngineers(): Collection
{
return $this->engineers;
}
public function addEngineer(Engineer $engineer): self
{
if (!$this->engineers->contains($engineer)) {
$this->engineers->add($engineer);
$engineer->setFactory($this);
}
return $this;
}
public function removeEngineer(Engineer $engineer): self
{
if ($this->engineers->removeElement($engineer)) {
// set the owning side to null (unless already changed)
if ($engineer->getFactory() === $this) {
$engineer->setFactory(null);
}
}
return $this;
}
/**
* @return Collection<int, Jobs>
*/
public function getJobs(): Collection
{
return $this->jobs;
}
public function addJob(Jobs $job): self
{
if (!$this->jobs->contains($job)) {
$this->jobs->add($job);
$job->setFactory($this);
}
return $this;
}
public function removeJob(Jobs $job): self
{
if ($this->jobs->removeElement($job)) {
// set the owning side to null (unless already changed)
if ($job->getFactory() === $this) {
$job->setFactory(null);
}
}
return $this;
}
}