<?php

namespace AppBundle\Entity\Product;

use AppBundle\Entity\Core\Tagg;
use AppBundle\Entity\Organization\Organization;
use Doctrine\ORM\Mapping as ORM;
use Dunglas\ApiBundle\Annotation\Iri;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use AppBundle\Annotation\DefaultField;
use AppBundle\Entity\Traits\TimestampableEntity;
use AppBundle\Entity\Traits\CreatorUpdaterEntity;
use AppBundle\Validator\Constraints\Product as OpentalentAssert;

/**
 * Classe de base de @see Equipment, Intangible
 *
 *
 */
#[ORM\Entity]
#[ORM\Table(name: 'Product')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'discr', type: 'string')]
#[ORM\DiscriminatorMap(['equipment' => 'Equipment', 'intangible' => 'Intangible'])]
abstract class AbstractProduct
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['equipment', 'intangible', 'equipment_list', 'equipmentrent_list', 'equipmentloan_list', 'equipmentcontrol_list', 'equipmentrepair_list', 'equipmentaccounting_list', 'equipmentmediatheque_list', 'equipmentcostume_list', 'intangible_list', 'place_list', 'examenconvocation_list', 'accessequipment_grid', 'access_details_equipmentloans', 'access_details', 'equipment_details', 'equipment_details_equipmentcomposition', 'own_access', 'own_student_access', 'event_details', 'course_details', 'educationalproject_details', 'booking_event', 'equipment_availability_form', 'examen_details', 'access_intangible_list'])]
    private $id;
    /**
     * @var Organization
     *
     * @DefaultField
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\Organization')]
    #[Groups(['equipment', 'intangible'])]
    private $organization;
    /**
     * @var string A short description of the item.
     *
     * @Iri("https://schema.org/description")
     */
    #[ORM\Column(type: 'text', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['equipment', 'intangible', 'intangible_list', 'equipment_details', 'equipment_list', 'equipmentmediatheque_list', 'equipmentcostume_list', 'equipmentrent_list', 'equipmentloan_list', 'equipmentcontrol_list', 'equipmentrepair_list', 'equipmentaccounting_list'])]
    private $description;
    /**
     * @var \DateTime
     *
     * @OpentalentAssert\EquipmentOutCauseDate
     */
    #[ORM\Column(type: 'date', nullable: true)]
    #[Assert\Date]
    #[Groups(['equipment', 'equipment_list', 'equipment_reference', 'equipmentloan_list_equipment', 'equipmentmediatheque_list', 'place_list_equipmentuseds', 'examenconvocation_list_equipments', 'equipment_details_equipmentcomposition', 'event_details_equipments', 'course_details_equipments', 'examen_details_equipments', 'educationalproject_details_equipments', 'equipment_details', 'equipmentrent_list_equipment', 'equipmentcostume_list'])]
    private $outCauseDate;
    /**
     * @var ArrayCollection<Tagg>
     */
    #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Core\Tagg', cascade: ['persist'], inversedBy: 'products')]
    #[Assert\Valid]
    #[ORM\JoinTable(name: 'tag_product', joinColumns: [], inverseJoinColumns: [])]
    #[ORM\JoinColumn(name: 'product_id', referencedColumnName: 'id')]
    #[ORM\JoinColumn(name: 'tag_id', referencedColumnName: 'id')]
    #[Groups(['product_tags', 'manage_tags', 'equipment_list', 'equipmentaccounting_list', 'equipmentcostume_list', 'equipmentmediatheque_list', 'intangible_list'])]
    private $tags;
    /**
     * The constructor
     */
    public function __construct() {
        $this->tags = new ArrayCollection();
    }
    /**
     * 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;
    }
    /**
     * Set description
     *
     * @param string $description
     *
     * @return AbstractProduct
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }
    /**
     * Get description
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }
    /**
     * Set organization
     *
     * @param \AppBundle\Entity\Organization\Organization $organization
     *
     * @return AbstractProduct
     */
    public function setOrganization(\AppBundle\Entity\Organization\Organization $organization = null)
    {
        $this->organization = $organization;

        return $this;
    }
    /**
     * Get organization
     *
     * @return \AppBundle\Entity\Organization\Organization
     */
    public function getOrganization()
    {
        return $this->organization;
    }
    /**
     * Sets outCauseDate.
     *
     * @param \DateTime $outCauseDate
     *
     * @return $this
     */
    public function setOutCauseDate(\DateTime $outCauseDate = null)
    {
        $this->outCauseDate = $outCauseDate;

        return $this;
    }
    /**
     * Gets outCauseDate.
     *
     * @return \DateTime
     */
    public function getOutCauseDate()
    {
        return $this->outCauseDate ? $this->outCauseDate->format('Y-m-d') : $this->outCauseDate;
    }
    /**
     * Add tag
     *
     * @param \AppBundle\Entity\Core\Tagg $tag
     *
     * @return AbstractProduct
     */
    public function addTag(\AppBundle\Entity\Core\Tagg $tag)
    {
        $this->tags[] = $tag;

        return $this;
    }
    /**
     * Remove tag
     *
     * @param \AppBundle\Entity\Core\Tagg $tag
     */
    public function removeTag(\AppBundle\Entity\Core\Tagg $tag)
    {
        $this->tags->removeElement($tag);
    }
    /**
     * Get tags
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getTags()
    {
        return $this->tags;
    }
}
