<?php

namespace AppBundle\Entity\AccessAndFunction;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Entity\Traits\TimestampableEntity;
use AppBundle\Entity\Traits\CreatorUpdaterEntity;

/**
 * Fais le lien entre les Access dont les titulaires sont membres d'une même famille
 * (cf. table 'children_guardians' pour les responsables légaux)
 */
#[ORM\Entity]
class AccessFamily
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['accessfamily', 'access_details', 'student_registration', 'access_informations_edit', 'online_registration_access_family'])]
    private $id;
    /**
     * @var ArrayCollection<Access>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', mappedBy: 'accessFamily')]
    #[Groups(['accessfamily_accesses', 'student_registration_accessfamily', 'access_informations_edit_accessfamily', 'access_details_accessfamily', 'online_registration_access_family_accessfamily'])]
    private $accesses;
    /**
     * @var ArrayCollection<AccessFictionalIntangible>
     */
    #[Assert\Valid]
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Billing\AccessFictionalIntangible', mappedBy: 'accessFamily', cascade: ['persist'], orphanRemoval: true)]
    #[Groups(['accessfamily_accessfictionalintangible'])]
    private $accessFictionalIntangibles;
    public function __construct()
    {
        $this->accesses = new ArrayCollection();
        $this->accessFictionalIntangibles = new ArrayCollection();
    }
    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * @param int $id
     * @return FunctionType
     */
    public function setId($id)
    {
        $this->id = $id;
        return $this;
    }
    /**
     * Add accessFictionalIntangible
     *
     * @param \AppBundle\Entity\Billing\AccessFictionalIntangible $accessFictionalIntangible
     *
     * @return AccessFamily
     */
    public function addAccessFictionalIntangible(\AppBundle\Entity\Billing\AccessFictionalIntangible $accessFictionalIntangible)
    {
        $this->accessFictionalIntangibles[] = $accessFictionalIntangible;

        return $this;
    }
    /**
     * Remove accessFictionalIntangible
     *
     * @param \AppBundle\Entity\Billing\AccessFictionalIntangible $accessFictionalIntangible
     */
    public function removeAccessFictionalIntangible(\AppBundle\Entity\Billing\AccessFictionalIntangible $accessFictionalIntangible)
    {
        $this->accessFictionalIntangibles->removeElement($accessFictionalIntangible);
    }
    /**
     * Get accessFictionalIntangibles
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getAccessFictionalIntangibles()
    {
        return $this->accessFictionalIntangibles;
    }
    /**
     * Add access
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $access
     *
     * @return AccessFamily
     */
    public function addAccess(\AppBundle\Entity\AccessAndFunction\Access $access)
    {
        $access->setAccessFamily($this);
        $this->accesses[] = $access;

        return $this;
    }
    /**
     * Remove access
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $access
     */
    public function removeAccess(\AppBundle\Entity\AccessAndFunction\Access $access)
    {
        $access->setAccessFamily(null);
        $this->accesses->removeElement($access);
    }
    /**
     * Get accesses
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getAccesses()
    {
        return $this->accesses;
    }
}
