<?php

namespace AppBundle\Entity\AccessAndFunction;
use AppBundle\Annotation\DefaultField;
use AppBundle\Annotation\ExportSplitFields;
use AppBundle\Entity\Traits\ActivityPeriodTrait;
use Doctrine\ORM\Mapping as ORM;
use Dunglas\ApiBundle\Annotation\Iri;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Entity\Traits\TimestampableEntity;
use AppBundle\Entity\Traits\CreatorUpdaterEntity;
use AppBundle\Entity\Organization\Activity;

/**
 * Fonction d'un Access dans une Organization sur une période donnée
 *
 * @Iri("http://schema.org/OrganizationFunction")
 */
#[ORM\Entity(repositoryClass: 'AppBundle\Entity\AccessAndFunction\Repository\OrganizationFunctionRepository')]
class OrganizationFunction
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    use ActivityPeriodTrait;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['organizationfunction', 'access_details', 'adherent_list', 'personnels_list', 'ca_list', 'accesses_list', 'othercontact_list', 'student_registration', 'student_registration_guardians', 'student_registration_accessfamily', 'board_list', 'licence_cmf', 'organization_function_edit', 'access_informations_edit', 'adherent_contact', 'cotisation_responsibles_accesses', 'view_from_manager_create', 'networkmanagers_list', 'online_registration_access_details', 'accesscmfnetwork'])]
    private $id;
    /**
     * @var Access
     */
    #[ORM\ManyToOne(targetEntity: 'Access', inversedBy: 'organizationFunction')]
    #[ORM\JoinColumn(nullable: false)]
    #[Assert\NotNull]
    #[Groups(['organizationfunction', 'organization_function_edit'])]
    private $access;
    /**
     * @var FunctionType
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\FunctionType')]
    #[ORM\JoinColumn(nullable: false)]
    #[Assert\NotNull]
    #[Groups(['organizationfunction', 'access_details_organizationfunction', 'adherent_list_organizationfunction', 'personnels_list_organizationfunction', 'othercontact_list_organizationfunction', 'ca_list_organizationfunction', 'accesses_list_organizationfunction', 'student_registration_organizationfunction', 'student_registration_guardians', 'student_registration_accessfamily', 'board_list_organizationfunction', 'licence_cmf_organizationfunction', 'access_informations_edit_organizationfunction', 'adherent_contact_organizationfunction', 'organization_function_edit', 'cotisation_responsibles_accesses_organizationfunction', 'view_from_manager_create_organizationfunction', 'networkmanagers_list_organizationfunction', 'online_registration_access_details_organizationfunction', 'accesscmfnetwork_organizationfunction'])]
    private $functionType;
    /**
     * @var string
     */
    #[ORM\Column(type: 'text', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['organizationfunction', 'access_details_organizationfunction', 'organization_function_edit', 'othercontact_list_organizationfunction', 'networkmanagers_list_organizationfunction', 'personnels_list_organizationfunction'])]
    private $functionComplement;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Choice(callback: ['\AppBundle\Enum\AccessAndFunction\DeparturesCauseEnum', 'toArray'])]
    #[Groups(['organizationfunction', 'accesses_list_organizationfunction', 'adherent_list_organizationfunction', 'personnels_list_organizationfunction', 'ca_list_organizationfunction', 'board_list_organizationfunction', 'access_details_organizationfunction', 'organization_function_edit', 'view_from_manager_create_organizationfunction'])]
    private $departureCause;
    /**
     * @var Activity
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\Activity')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    #[Groups(['organizationfunction', 'access_details_organizationfunction', 'organization_function_edit'])]
    private $activity;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => true])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['organizationfunction', 'organization_function_edit'])]
    private $isMemberSection = true;
    /**
     * @var string
     * @ExportSplitFields({"functionType.mission","startDate","endDate"})
     */
    #[Groups(['template'])]
    private $fullLabelTemplate;
    /**
     * Sets id.
     * 
     * @param int $id
     * 
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }
    /**
     * Gets id.
     * 
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Sets functionType.
     * 
     * @param string $functionType
     * 
     * @return $this
     */
    public function setFunctionType($functionType)
    {
        $this->functionType = $functionType;

        return $this;
    }
    /**
     * Get functionType
     *
     * @return \AppBundle\Entity\AccessAndFunction\FunctionType
     */
    public function getFunctionType()
    {
        return $this->functionType;
    }
    /**
     * Sets functionComplement.
     * 
     * @param string $functionComplement
     * 
     * @return $this
     */
    public function setFunctionComplement($functionComplement)
    {
        $this->functionComplement = $functionComplement;

        return $this;
    }
    /**
     * Gets functionComplement.
     * 
     * @return string
     */
    public function getFunctionComplement()
    {
        return $this->functionComplement;
    }
    /**
     * Sets departureCause.
     * 
     * @param string $departureCause
     * 
     * @return $this
     */
    public function setDepartureCause($departureCause)
    {
        $this->departureCause = $departureCause;

        return $this;
    }
    /**
     * Gets departureCause.
     * 
     * @return string
     */
    public function getDepartureCause()
    {
        return $this->departureCause;
    }
    /**
     * Sets activity.
     * 
     * @param Activity $activity
     * 
     * @return $this
     */
    public function setActivity(Activity $activity = null)
    {
        $this->activity = $activity;

        return $this;
    }
    /**
     * Gets activity.
     * 
     * @return Activity
     */
    public function getActivity()
    {
        return $this->activity;
    }
    /**
     * Set access
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $access
     *
     * @return OrganizationFunction
     */
    public function setAccess(\AppBundle\Entity\AccessAndFunction\Access $access)
    {
        $this->access = $access;

        return $this;
    }
    /**
     * Get access
     *
     * @return \AppBundle\Entity\AccessAndFunction\Access
     */
    public function getAccess()
    {
        return $this->access;
    }
    /**
     * Sets isMemberSection.
     *
     * @param bool $isMemberSection
     *
     * @return $this
     */
    public function setIsPhysical($isMemberSection)
    {
        $this->isMemberSection = $isMemberSection;

        return $this;
    }
    /**
     * Gets isMemberSection.
     *
     * @return bool
     */
    public function getIsPhysical()
    {
        return $this->isMemberSection;
    }
    /**
     * Set isMemberSection
     *
     * @param boolean $isMemberSection
     *
     * @return OrganizationFunction
     */
    public function setIsMemberSection($isMemberSection)
    {
        $this->isMemberSection = $isMemberSection;

        return $this;
    }
    /**
     * Get isMemberSection
     *
     * @return boolean
     */
    public function getIsMemberSection()
    {
        return $this->isMemberSection;
    }
    /**
     * @return array
     * @throws \Exception
     */
    public function getFullLabelTemplate()
    {
        $startDate = new \DateTime($this->getStartDate());


        $fullLabelTemplate = [
            ['value' => $this->getFunctionType()->getMission(), 'translate' => true],
            $startDate->format('d-m-Y')
        ];

        if(!empty($this->getEndDate())){
            $endDate = new \DateTime($this->getEndDate());
            $fullLabelTemplate[] = $endDate->format('d-m-Y');
        }

        return $fullLabelTemplate;
    }
}
