<?php

namespace AppBundle\Entity\Billing;

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

/**
 * Fais le lien entre l'Access qui règle la facture et l'Access concerné
 *
 *
 * @Iri("http://schema.org/AccessPayer")
 */
#[ORM\Entity]
class AccessPayer extends AbstractBillingPayer
{
    /**
     * @var Access
     */
    #[Assert\Valid]
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'billingPayers')]
    #[Groups(['accesspayer', 'access_details_billingpayers', 'student_registration_billingreceivers', 'accessbilling_edit_billingreceivers', 'access_intangible_list_access'])]
    private $accessPayer;
    /**
     * @var Access
     */
    #[Assert\Valid]
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'billingReceivers')]
    #[Groups(['accesspayer', 'access_details_billingpayers', 'student_registration_billingreceivers', 'payer_list_billingpayers', 'accessbilling_edit_billingpayers'])]
    private $accessReceiver;
    /**
     * @var string
     * @ExportSplitFields({"accessReceiver.person.name","accessReceiver.person.givenName","paymentPart"})
     */
    #[Groups(['template', 'payer_list_billingpayers'])]
    private $fullLabelReceiverTemplate;
    /**
     * Set accessPayer
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $accessPayer
     *
     * @return AccessPayer
     */
    public function setAccessPayer(\AppBundle\Entity\AccessAndFunction\Access $accessPayer)
    {
        $this->accessPayer = $accessPayer;

        return $this;
    }
    /**
     * Get accessPayer
     *
     * @return \AppBundle\Entity\AccessAndFunction\Access
     */
    public function getAccessPayer()
    {
        return $this->accessPayer;
    }
    /**
     * Set accessReceiver
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $accessReceiver
     *
     * @return AccessPayer
     */
    public function setAccessReceiver(\AppBundle\Entity\AccessAndFunction\Access $accessReceiver)
    {
        $this->accessReceiver = $accessReceiver;

        return $this;
    }
    /**
     * Get accessReceiver
     *
     * @return \AppBundle\Entity\AccessAndFunction\Access
     */
    public function getAccessReceiver()
    {
        return $this->accessReceiver;
    }
    /**
     * @return array
     */
    public function getFullLabelReceiverTemplate()
    {
        return  [
            $this->getAccessReceiver()->getPerson()->getFullNameTemplate(),
            $this->getPaymentPart().'%'
        ];
    }
}
