<?php

namespace AppBundle\Entity\Billing;

use AppBundle\Entity\AccessAndFunction\Access;
use AppBundle\Entity\Booking\EducationalProject;
use AppBundle\Entity\Product\Intangible;
use AppBundle\Entity\Traits\LockableTrait;
use AppBundle\Enum\Billing\PeriodicityTypeEnum;
use Doctrine\Common\Collections\ArrayCollection;
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 Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

/**
 * Fais le lien entre l'Access qui règle la facture et l'EducationalProject concerné
 *
 * @Iri("http://schema.org/EducationalProjectIntangible")
 */
#[ORM\Entity]
class EducationalProjectIntangible extends AbstractBillingIntangible
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    use LockableTrait;
    /**
     * @var EducationalProject
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Booking\EducationalProject', inversedBy: 'educationalProjectIntangibles')]
    #[Groups(['educationalprojectintangible'])]
    private $educationalProject;
    /**
     * @var ArrayCollection<BillingIntangibleExcludeDate>
     */
    #[Assert\Valid]
    #[ORM\OneToMany(targetEntity: 'BillingIntangibleExcludeDate', mappedBy: 'educationalProjectIntangible', cascade: ['persist'], orphanRemoval: true)]
    #[Groups(['accessintangible'])]
    private $billingIntangibleExcludeDates;
    /**
     * @var float
     */
    #[ORM\Column(type: 'float', nullable: true)]
    #[Assert\Type(type: 'float')]
    #[Groups(['educationalprojectintangible'])]
    private $unitPrice;
    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct();
        $this->billingIntangibleExcludeDates = new ArrayCollection();
    }
    /**
     * Set educationalProject
     *
     * @param \AppBundle\Entity\Booking\EducationalProject $educationalProject
     *
     * @return EducationalProjectIntangible
     */
    public function setEducationalProject(\AppBundle\Entity\Booking\EducationalProject $educationalProject)
    {
        $this->educationalProject = $educationalProject;

        return $this;
    }
    /**
     * Get educationalProject
     *
     * @return \AppBundle\Entity\Booking\EducationalProject
     */
    public function getEducationalProject()
    {
        return $this->educationalProject;
    }
    /**
     * applyLock
     */
    public function applyLock()
    {
//        if(!is_null($this->getExcludeRule()) && $this->getIntangible()->getBillingPeriodicityType() === PeriodicityTypeEnum::PUNCTUAL){
//            $this->setLockable(true);
//        }
    }
    public function adminCanChange(){
        return false;
    }
    /**
     * Add billingIntangibleExcludeDate
     *
     * @param \AppBundle\Entity\Billing\BillingIntangibleExcludeDate $billingIntangibleExcludeDate
     *
     * @return EducationalProjectIntangible
     */
    public function addBillingIntangibleExcludeDate(\AppBundle\Entity\Billing\BillingIntangibleExcludeDate $billingIntangibleExcludeDate)
    {
        $this->billingIntangibleExcludeDates[] = $billingIntangibleExcludeDate;

        return $this;
    }
    /**
     * Remove billingIntangibleExcludeDate
     *
     * @param \AppBundle\Entity\Billing\BillingIntangibleExcludeDate $billingIntangibleExcludeDate
     */
    public function removeBillingIntangibleExcludeDate(\AppBundle\Entity\Billing\BillingIntangibleExcludeDate $billingIntangibleExcludeDate)
    {
        $this->billingIntangibleExcludeDates->removeElement($billingIntangibleExcludeDate);
    }
    /**
     * Get billingIntangibleExcludeDates
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getBillingIntangibleExcludeDates()
    {
        return $this->billingIntangibleExcludeDates;
    }
    /**
     * Set unitPrice
     *
     * @param float $unitPrice
     *
     * @return EducationalProjectIntangible
     */
    public function setUnitPrice($unitPrice)
    {
        $this->unitPrice = floatval($unitPrice);

        return $this;
    }
    /**
     * Get unitPrice
     *
     * @return float
     */
    public function getUnitPrice()
    {
        return $this->unitPrice;
    }
}
