<?php
declare (strict_types=1);

namespace App\Entity\Access;

use ApiPlatform\Metadata\ApiResource;
use App\Attribute\DateTimeConstraintAware;
use App\Entity\Organization\Activity;
use App\Entity\Traits\ActivityPeriodTrait;
use App\Repository\Access\OrganizationFunctionRepository;
//use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Fonction d'un Access dans une Organization sur une période donnée
 */
#[ApiResource]
//#[Auditable]
#[ORM\Entity(repositoryClass: OrganizationFunctionRepository::class)]
#[DateTimeConstraintAware(startDateFieldName: "startDate", endDateFieldName: "endDate")]
class OrganizationFunction
{
    use ActivityPeriodTrait;

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'organizationFunction')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Access $access = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false)]
    private FunctionType $functionType;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $functionComplement = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private Activity $activity;

    #[ORM\Column(length: 255, nullable: true)]
    #[Assert\Choice(callback: ['\\App\\Enum\\Access\\DeparturesCauseEnum', 'toArray'], message: 'invalid-departure-cause')]
    private ?string $departureCause = null;

    #[ORM\Column(options: ['default' => true])]
    private bool $isMemberSection = true;

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

    public function getAccess(): ?Access
    {
        return $this->access;
    }

    public function setAccess(?Access $access): self
    {
        $this->access = $access;
        return $this;
    }

    public function setFunctionType(FunctionType $functionType): self
    {
        $this->functionType = $functionType;
        return $this;
    }

    public function getFunctionType(): FunctionType
    {
        return $this->functionType;
    }

    public function getFunctionComplement(): ?string
    {
        return $this->functionComplement;
    }

    public function setFunctionComplement(?string $functionComplement): self
    {
        $this->functionComplement = $functionComplement;
        return $this;
    }

    public function setDepartureCause(?string $departureCause): self
    {
        $this->departureCause = $departureCause;
        return $this;
    }

    public function getDepartureCause(): ?string
    {
        return $this->departureCause;
    }

    public function setIsMemberSection(bool $isMemberSection): self
    {
        $this->isMemberSection = $isMemberSection;
        return $this;
    }

    public function getIsMemberSection(): bool
    {
        return $this->isMemberSection;
    }

    public function getActivity(): ?Activity
    {
        return $this->activity;
    }

    public function setActivity(?Activity $activity): self
    {
        $this->activity = $activity;
        return $this;
    }
}
