<?php

namespace AppBundle\Entity\Billing;

use AppBundle\Entity\AccessAndFunction\Access;
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;

/**
 * Enregistrement d'un produit à facturer par un Access
 *
 * @Iri("http://schema.org/AccessIntangible")
 */
#[ORM\Entity(repositoryClass: 'AppBundle\Entity\Billing\Repository\AccessIntangibleRepository')]
class AccessIntangible extends AbstractBillingIntangible
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    use LockableTrait;
    /**
     * @var Access
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'accessIntangibles')]
    #[Groups(['accessintangible', 'access_intangible_list'])]
    private $access;
    /**
     * @var ArrayCollection<BillingIntangibleExcludeDate>
     */
    #[Assert\Valid]
    #[ORM\OneToMany(targetEntity: 'BillingIntangibleExcludeDate', mappedBy: 'accessIntangible', cascade: ['persist'], orphanRemoval: true)]
    #[Groups(['accessintangible', 'student_registration_accessintangibles', 'accessbilling_edit_accessintangibles'])]
    private $billingIntangibleExcludeDates;
    /**
     * @var float
     */
    #[ORM\Column(type: 'float', nullable: true)]
    #[Assert\Type(type: 'float')]
    #[Groups(['accessintangible', 'educationalprojectintangible', 'student_registration_accessintangibles', 'accessbilling_edit_accessintangibles'])]
    private $unitPrice;
    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct();
        $this->billingIntangibleExcludeDates = new ArrayCollection();
    }
    /**
     * Set access
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $access
     *
     * @return AccessIntangible
     */
    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;
    }
    /**
     * 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 AccessIntangible
     */
    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 AccessIntangible
     */
    public function setUnitPrice($unitPrice)
    {
        $this->unitPrice = floatval($unitPrice);

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