<?php

namespace AppBundle\Entity\AccessWish;

use AppBundle\Entity\Organization\Organization;
use AppBundle\Entity\Traits\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Contient les access temporaires d'une organisation = les email qui ont fait la procédure signin
 */
#[ORM\Entity]
class AccessTmp
{
    use TimestampableEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    private $id;
    /**
     * @var Organization
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\Organization')]
    private $organization;
    /**
     * @var string
     */
    #[Assert\Type(type: 'string')]
    #[ORM\Column(type: 'string', nullable: true)]
    private $mail;
    /**
     * @var string
     */
    #[Assert\Type(type: 'string')]
    #[ORM\Column(type: 'string', nullable: true)]
    private $username;
    /**
     * @var string
     */
    #[Assert\Type(type: 'string')]
    #[ORM\Column(type: 'string', nullable: true)]
    private $password;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 100, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Length(max: 100, maxMessage: 'invalid-max-length')]
    private $name;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 50, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Length(max: 50, maxMessage: 'invalid-max-length')]
    private $givenName;
    /**
     * @var \DateTime Date of birth.
     */
    #[ORM\Column(type: 'date', nullable: true)]
    #[Assert\Date(message: 'invalid-date')]
    private $birthDate;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    private $informationRetainedAndUsed = false;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Assert\Type(type: 'boolean')]
    #[Assert\NotNull]
    private $cgu = false;
    /**
     * Random string sent to the user email address in order to verify it
     *
     * @var string
     */
    #[ORM\Column(name: 'confirmation_token', type: 'string', nullable: false)]
    private $confirmationToken;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'datetime', nullable: false)]
    private $tokenGivenDate;
    public function __construct()
    {

    }
    /**
     * 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 organization.
     *
     * @param Organization $organization
     *
     * @return $this
     */
    public function setOrganization(Organization $organization = null)
    {
        $this->organization = $organization;

        return $this;
    }
    /**
     * Gets organization.
     *
     * @return Organization
     */
    public function getOrganization()
    {
        return $this->organization;
    }
    /**
     * Sets mail.
     *
     * @param string $mail
     *
     * @return $this
     */
    public function setMail($mail)
    {
        $this->mail = $mail;

        return $this;
    }
    /**
     * Gets mail.
     *
     * @return string
     */
    public function getMail()
    {
        return $this->mail;
    }
    /**
     * Sets username.
     *
     * @param string $username
     *
     * @return $this
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }
    /**
     * Gets username.
     *
     * @return string
     */
    public function getUsername()
    {
        return $this->username;
    }
    /**
     * Sets password.
     *
     * @param string $password
     *
     * @return $this
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }
    /**
     * Gets password.
     *
     * @return string
     */
    public function getPassword()
    {
        return $this->password;
    }
    /**
     * Sets confirmation token.
     *
     * @param string $token
     *
     * @return $this
     */
    public function setConfirmationToken($token)
    {
        $this->confirmationToken = $token;

        return $this;
    }
    /**
     * Gets confirmation token.
     *
     * @return string
     */
    public function getConfirmationToken()
    {
        return $this->confirmationToken;
    }
    /**
     * set token given date
     * @param \DateTime $tokenGivenDate
     * @return $this
     */
    public function setTokenGivenDate(\DateTime $tokenGivenDate)
    {
        $this->tokenGivenDate = $tokenGivenDate;
        return $this;
    }
    /**
     * Gets token given date
     *
     * @return \DateTime
     */
    public function getTokenGivenDate()
    {
        return $this->tokenGivenDate;
    }
    public function isTokenNonExpired($ttl)
    {
        return $this->getTokenGivenDate() instanceof \DateTime &&
            $this->getTokenGivenDate()->getTimestamp() + $ttl > time();
    }
    /**
     * Set name
     *
     * @param string $name
     *
     * @return AccessTmp
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }
    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
    /**
     * Set givenName
     *
     * @param string $givenName
     *
     * @return AccessTmp
     */
    public function setGivenName($givenName)
    {
        $this->givenName = $givenName;

        return $this;
    }
    /**
     * Get givenName
     *
     * @return string
     */
    public function getGivenName()
    {
        return $this->givenName;
    }
    /**
     * Set birthDate
     *
     * @param \DateTime $birthDate
     *
     * @return AccessTmp
     */
    public function setBirthDate($birthDate)
    {
        $this->birthDate = $birthDate;

        return $this;
    }
    /**
     * Get birthDate
     *
     * @return \DateTime
     */
    public function getBirthDate()
    {
        return $this->birthDate;
    }
    /**
     * Set informationRetainedAndUsed
     *
     * @param boolean $informationRetainedAndUsed
     *
     * @return AccessTmp
     */
    public function setInformationRetainedAndUsed($informationRetainedAndUsed)
    {
        $this->informationRetainedAndUsed = $informationRetainedAndUsed;

        return $this;
    }
    /**
     * Get informationRetainedAndUsed
     *
     * @return boolean
     */
    public function getInformationRetainedAndUsed()
    {
        return $this->informationRetainedAndUsed;
    }
    /**
     * Set cgu
     *
     * @param boolean $cgu
     *
     * @return AccessTmp
     */
    public function setCgu($cgu)
    {
        $this->cgu = $cgu;

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