<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\TMainStructureLevelsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource(
 *    normalizationContext={"groups"={"t_main_structure_levels:read"}, "enable_max_depth"="true", "swagger_definition_name"="Read"},
 *    denormalizationContext={"groups"={"t_main_structure_levels:write"}, "swagger_definition_name"="Write"}
 * )
 * @ApiFilter(SearchFilter::class, properties={ "id": "exact", "status": "exact" })
 * @ApiFilter(PropertyFilter::class)
 * @ORM\Entity(repositoryClass=TMainStructureLevelsRepository::class)
 */

class TMainStructureLevels
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({ "t_main_structure_levels:read", "t_main_structure_levels:write", "t_main_structure_offices:read", "t_staff_members:read" })
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({ "t_main_structure_levels:read", "t_main_structure_levels:write", "t_main_structure_offices:read", "t_staff_members:read" })
     */
    private $name;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({ "t_main_structure_levels:read", "t_main_structure_levels:write" })
     */
    private $status;

    /**
     * @ORM\OneToMany(targetEntity=TMainStructureOffices::class, mappedBy="mainStructureLevel")
     * @Groups({ "t_main_structure_levels:read", "t_main_structure_levels:write" })
     */
    private $tMainStructureOffices;

    /**
     * @ORM\OneToMany(targetEntity=TMainTargetsPlannings::class, mappedBy="mainStructureLevel")
     * @Groups({ "t_main_structure_levels:read", "t_main_structure_levels:write" })
     */
    private $tMainTargetsPlannings;

    public function __construct()
    {
        $this->tMainStructureOffices = new ArrayCollection();
        $this->tMainTargetsPlannings = 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 getStatus(): ?string
    {
        return $this->status;
    }

    public function setStatus(?string $status): self
    {
        $this->status = $status;

        return $this;
    }

    /**
     * @return Collection|TMainStructureOffices[]
     */
    public function getTMainStructureOffices(): Collection
    {
        return $this->tMainStructureOffices;
    }

    public function addTMainStructureOffice(TMainStructureOffices $tMainStructureOffice): self
    {
        if (!$this->tMainStructureOffices->contains($tMainStructureOffice)) {
            $this->tMainStructureOffices[] = $tMainStructureOffice;
            $tMainStructureOffice->setMainStructureLevel($this);
        }

        return $this;
    }

    public function removeTMainStructureOffice(TMainStructureOffices $tMainStructureOffice): self
    {
        if ($this->tMainStructureOffices->removeElement($tMainStructureOffice)) {
            // set the owning side to null (unless already changed)
            if ($tMainStructureOffice->getMainStructureLevel() === $this) {
                $tMainStructureOffice->setMainStructureLevel(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|TMainTargetsPlannings[]
     */
    public function getTMainTargetsPlannings(): Collection
    {
        return $this->tMainTargetsPlannings;
    }

    public function addTMainTargetsPlanning(TMainTargetsPlannings $tMainTargetsPlanning): self
    {
        if (!$this->tMainTargetsPlannings->contains($tMainTargetsPlanning)) {
            $this->tMainTargetsPlannings[] = $tMainTargetsPlanning;
            $tMainTargetsPlanning->setMainStructureLevel($this);
        }

        return $this;
    }

    public function removeTMainTargetsPlanning(TMainTargetsPlannings $tMainTargetsPlanning): self
    {
        if ($this->tMainTargetsPlannings->removeElement($tMainTargetsPlanning)) {
            // set the owning side to null (unless already changed)
            if ($tMainTargetsPlanning->getMainStructureLevel() === $this) {
                $tMainTargetsPlanning->setMainStructureLevel(null);
            }
        }

        return $this;
    }
}
