<?php

declare(strict_types=1);

namespace App\Entity\Organization;

use ApiPlatform\Metadata\ApiResource;
use App\Enum\Cotisation\CategoryTypeOfPracticeEnum;
use App\Enum\Cotisation\TypeOfPracticeEnum;
use App\Repository\Organization\TypeOfPracticeRepository;
// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JetBrains\PhpStorm\Pure;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * Type des pratique d'une organisation.
 */
#[ApiResource(operations: [])]
// #[Auditable]
#[ORM\Entity(repositoryClass: TypeOfPracticeRepository::class)]
class TypeOfPractice
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    #[Groups(['read'])]
    private ?int $id = null;

    #[ORM\Column(length: 50, nullable: true, enumType: TypeOfPracticeEnum::class)]
    #[Groups(['read'])]
    private ?TypeOfPracticeEnum $name = null;

    #[ORM\Column(length: 50, nullable: true, enumType: CategoryTypeOfPracticeEnum::class)]
    #[Groups(['read'])]
    private ?CategoryTypeOfPracticeEnum $category = null;

    /** @var Collection<int, Organization> */
    #[ORM\ManyToMany(targetEntity: Organization::class, inversedBy: 'typeOfPractices')]
    #[ORM\JoinTable(name: 'organization_type_of_practices')]
    #[ORM\JoinColumn(name: 'typeofpractice_id', referencedColumnName: 'id')]
    #[ORM\InverseJoinColumn(name: 'organization_id', referencedColumnName: 'id')]
    private Collection $organizations;

    #[Pure]
    public function __construct()
    {
        $this->organizations = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?TypeOfPracticeEnum
    {
        return $this->name;
    }

    public function setName(?TypeOfPracticeEnum $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getCategory(): ?CategoryTypeOfPracticeEnum
    {
        return $this->category;
    }

    public function setCategory(?CategoryTypeOfPracticeEnum $category): self
    {
        $this->category = $category;

        return $this;
    }

    public function getOrganizations(): Collection
    {
        return $this->organizations;
    }

    public function addOrganization(Organization $organization): self
    {
        if (!$this->organizations->contains($organization)) {
            $this->organizations[] = $organization;
            $organization->addTypeOfPractice($this);
        }

        return $this;
    }

    public function removeOrganization(Organization $organization): self
    {
        if ($this->organizations->removeElement($organization)) {
            $organization->removeTypeOfPractice($this);
        }

        return $this;
    }
}
