<?php

namespace AppBundle\Entity\AccessWish;

use AppBundle\Enum\OnlineRegistration\StatusEnum;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use DoctrineExtensions\Query\Mysql\Date;
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;

/**
 * Access.
 *
 * @see http://schema.org/AccessFamilyWish Documentation on Schema.org
 *
 * @Iri("http://schema.org/AccessFamilyWish")
 */
#[ORM\Entity]
class AccessFamilyWish
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['accessfamilywish', 'access_familly_onlineregistration', 'online_registration_access_family_accesswishes', 'online_registration_validation_access_family_accesswish', 'online_registration_validation_access_family_accesswishreregistrations', 'accesswish_mail'])]
    private $id;
    /**
     * @var ArrayCollection<AccessWish>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\AccessWish\AccessWish', mappedBy: 'accessFamilyWish', cascade: ['remove'])]
    #[Groups(['accessfamilywish_accesswishes', 'access_familly_onlineregistration', 'online_registration_access_family_accesswishes', 'online_registration_validation_access_family_accesswish', 'online_registration_validation_access_family_accesswishreregistrations', 'accesswish_mail_accessfamilywish'])]
    private $accessWishes;
    /**
     * @var ArrayCollection<AccessWish>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\AccessWish\AccessWish', mappedBy: 'accessFamilyWish', cascade: ['remove'], fetch: 'EXTRA_LAZY')]
    #[Groups(['accessfamilywish_accesswishes', 'education_student_wish_list_accesswishreregistrations', 'education_student_wish_list_accesswish'])]
    private $accessWishesGuardians;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['accessfamilywish', 'access_familly_onlineregistration'])]
    private $registrationCompleted = false;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'datetime', nullable: true)]
    #[Assert\Date]
    #[Groups(['accessfamilywish', 'access_familly_onlineregistration'])]
    private $registrationCompletedDateTime;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['accessfamilywish'])]
    private $registrationIsValidated = false;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    #[Groups(['accessfamilywish'])]
    private $closeRegistration = false;
    public function __construct()
    {
        $this->accessWishes = new ArrayCollection();
    }
    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * @param $registrationCompleted
     * @return $this
     * @throws \Exception
     */
    public function setRegistrationCompleted($registrationCompleted)
    {
        if(!$registrationCompleted)
            return $this;
        if(empty($this->getRegistrationCompletedDateTime()))
            $this->setRegistrationCompletedDateTime(new \DateTime());
        $this->registrationCompleted = $registrationCompleted;

        return $this;
    }
    /**
     * Get registrationCompleted
     *
     * @return boolean
     */
    public function getRegistrationCompleted()
    {
        return $this->registrationCompleted;
    }
    /**
     * Add accessWish
     *
     * @param \AppBundle\Entity\AccessWish\AccessWish $accessWish
     *
     * @return AccessFamilyWish
     */
    public function addAccessWish(\AppBundle\Entity\AccessWish\AccessWish $accessWish)
    {
        $accessWish->setAccessFamilyWish($this);
        $this->accessWishes[] = $accessWish;

        return $this;
    }
    /**
     * Remove accessWish
     *
     * @param \AppBundle\Entity\AccessWish\AccessWish $accessWish
     */
    public function removeAccessWish(\AppBundle\Entity\AccessWish\AccessWish $accessWish)
    {
        $accessWish->setAccessFamilyWish(null);
        $this->accessWishes->removeElement($accessWish);
    }
    /**
     * Get accessWishes
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getAccessWishes()
    {
        return $this->accessWishes;
    }
    public function getAccessWishesGuardians()
    {
        $guardians = [];
        foreach ($this->accessWishes as $accessWish){
            if($accessWish->getStatus() === StatusEnum::RESPONSIBLE)
                $guardians[] = $accessWish;
        }
        return $guardians;
    }
    /**
     * Set registrationCompletedDateTime
     *
     * @param \DateTime $registrationCompletedDateTime
     *
     * @return AccessFamilyWish
     */
    public function setRegistrationCompletedDateTime($registrationCompletedDateTime)
    {
        $this->registrationCompletedDateTime = $registrationCompletedDateTime;

        return $this;
    }
    /**
     * Get registrationCompletedDateTime
     *
     * @return \DateTime
     */
    public function getRegistrationCompletedDateTime()
    {
        return $this->registrationCompletedDateTime;
    }
    /**
     * Set registrationIsValidated
     *
     * @param boolean $registrationIsValidated
     *
     * @return AccessFamilyWish
     */
    public function setRegistrationIsValidated($registrationIsValidated)
    {
        $this->registrationIsValidated = $registrationIsValidated;

        return $this;
    }
    /**
     * Get registrationIsValidated
     *
     * @return boolean
     */
    public function getRegistrationIsValidated()
    {
        return $this->registrationIsValidated;
    }
    /**
     * Set closeRegistration
     *
     * @param boolean $closeRegistration
     *
     * @return AccessFamilyWish
     */
    public function setCloseRegistration($closeRegistration)
    {
        $this->closeRegistration = $closeRegistration;

        return $this;
    }
    /**
     * Get closeRegistration
     *
     * @return boolean
     */
    public function getCloseRegistration()
    {
        return $this->closeRegistration;
    }
}
