<?php

namespace AppBundle\Entity\Core;

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

/**
 * Contrôle du bon état des Place, Room et Equipment, effectué ou planifié
 * Classe de base de @see PlaceControl, RoomControl, EquipmentControl
 *
 * @author vincent
 *
 */
#[ORM\Entity]
#[ORM\Table(name: 'Control')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'discr', type: 'string')]
#[ORM\DiscriminatorMap(['place' => 'AppBundle\Entity\Place\PlaceControl', 'room' => 'AppBundle\Entity\Place\RoomControl', 'equipment' => 'AppBundle\Entity\Product\EquipmentControl'])]
abstract class AbstractControl
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    use ActivityPeriodTrait;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['control', 'equipmentcontrol_list', 'placecontrol_list', 'equipment_details', 'control_edit'])]
    private $id;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Choice(callback: ['\AppBundle\Enum\Product\ControlTypeEnum', 'toArray'])]
    #[Groups(['control', 'equipmentcontrol_list', 'placecontrol_list', 'equipment_details_equipmentcontrol', 'control_edit'])]
    private $controlType;
    /**
     * @var bool
     */
    #[ORM\Column(type: 'boolean', nullable: true)]
    #[Assert\Type(type: 'boolean')]
    #[Groups(['control', 'equipmentcontrol_list', 'placecontrol_list', 'control_edit'])]
    private $report;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['control', 'equipmentcontrol_list', 'placecontrol_list', 'equipment_details_equipmentcontrol', 'control_edit'])]
    private $operator;
    /**
     * @var string
     */
    #[ORM\Column(type: 'text', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['control', 'equipmentcontrol_list', 'placecontrol_list', 'control_edit'])]
    private $finding;
    /**
     * @var string
     */
    #[ORM\Column(type: 'text', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['control', 'equipmentcontrol_list', 'placecontrol_list', 'control_edit'])]
    private $workDoing;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer', nullable: true)]
    #[Assert\Type(type: 'integer', message: 'invalid-integer')]
    #[Groups(['control', 'equipmentcontrol_list', 'equipment_details_equipmentcontrol', 'control_edit'])]
    private $lifeBalance;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer', nullable: true)]
    #[Assert\Type(type: 'integer', message: 'invalid-integer')]
    #[Groups(['control', 'equipmentcontrol_list', 'control_edit'])]
    private $usedDuration;
    /**
     * @var Access
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'accompanistControl')]
    #[ORM\JoinColumn(nullable: true)]
    #[Groups(['control', 'equipmentcontrol_list', 'control_edit'])]
    private $accompanist;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer', nullable: true)]
    #[Assert\Type(type: 'integer', message: 'invalid-integer')]
    #[Groups(['control', 'equipmentcontrol_list', 'equipment_details_equipmentcontrol', 'control_edit'])]
    private $balanceUsefulLife;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'date', nullable: true)]
    #[Assert\Date]
    #[Groups(['control', 'equipmentcontrol_list', 'placecontrol_list', 'equipment_details_equipmentcontrol', 'control_edit'])]
    private $nextControl;
    /**
     * @var ArrayCollection<Tagg>
     */
    #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Core\Tagg', cascade: ['persist'], inversedBy: 'controls')]
    #[Assert\Valid]
    #[ORM\JoinTable(name: 'tag_control', joinColumns: [], inverseJoinColumns: [])]
    #[ORM\JoinColumn(name: 'control_id', referencedColumnName: 'id')]
    #[ORM\JoinColumn(name: 'tag_id', referencedColumnName: 'id')]
    #[Groups(['control_tags', 'manage_tags', 'equipmentcontrol_list'])]
    private $tags;
    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;
    }
    /**
     * Sets controlType.
     *
     * @param string $controlType
     *
     * @return $this
     */
    public function setControlType($controlType)
    {
        $this->controlType = $controlType;

        return $this;
    }
    /**
     * Gets controlType.
     *
     * @return string
     */
    public function getControlType()
    {
        return $this->controlType;
    }
    /**
     * Sets report.
     *
     * @param bool $report
     *
     * @return $this
     */
    public function setReport($report)
    {
        $this->report = $report;

        return $this;
    }
    /**
     * Gets report.
     *
     * @return bool
     */
    public function getReport()
    {
        return $this->report;
    }
    /**
     * Sets operator.
     *
     * @param string $operator
     *
     * @return $this
     */
    public function setOperator($operator)
    {
        $this->operator = $operator;

        return $this;
    }
    /**
     * Gets operator.
     *
     * @return string
     */
    public function getOperator()
    {
        return $this->operator;
    }
    /**
     * Sets finding.
     *
     * @param string $finding
     *
     * @return $this
     */
    public function setFinding($finding)
    {
        $this->finding = $finding;

        return $this;
    }
    /**
     * Gets finding.
     *
     * @return string
     */
    public function getFinding()
    {
        return $this->finding;
    }
    /**
     * Sets workDoing.
     *
     * @param string $workDoing
     *
     * @return $this
     */
    public function setWorkDoing($workDoing)
    {
        $this->workDoing = $workDoing;

        return $this;
    }
    /**
     * Gets workDoing.
     *
     * @return string
     */
    public function getWorkDoing()
    {
        return $this->workDoing;
    }
    /**
     * Sets lifeBalance.
     *
     * @param int $lifeBalance
     *
     * @return $this
     */
    public function setLifeBalance($lifeBalance)
    {
        $this->lifeBalance = $lifeBalance;

        return $this;
    }
    /**
     * Gets lifeBalance.
     *
     * @return int
     */
    public function getLifeBalance()
    {
        return $this->lifeBalance;
    }
    /**
     * Sets usedDuration.
     *
     * @param int $usedDuration
     *
     * @return $this
     */
    public function setUsedDuration($usedDuration)
    {
        $this->usedDuration = $usedDuration;

        return $this;
    }
    /**
     * Gets usedDuration.
     *
     * @return int
     */
    public function getUsedDuration()
    {
        return $this->usedDuration;
    }
    /**
     * @param Access|null $accompanist
     * @return $this
     */
    public function setAccompanist(Access $accompanist = null)
    {
        $this->accompanist = $accompanist;

        return $this;
    }
    /**
     * Gets accompanist.
     *
     * @return Access
     */
    public function getAccompanist()
    {
        return $this->accompanist;
    }
    /**
     * Sets balanceUsefulLife.
     *
     * @param int $balanceUsefulLife
     *
     * @return $this
     */
    public function setBalanceUsefulLife($balanceUsefulLife)
    {
        $this->balanceUsefulLife = $balanceUsefulLife;

        return $this;
    }
    /**
     * Gets balanceUsefulLife.
     *
     * @return int
     */
    public function getBalanceUsefulLife()
    {
        return $this->balanceUsefulLife;
    }
    /**
     * Sets nextControl.
     *
     * @param \DateTime $nextControl
     *
     * @return $this
     */
    public function setNextControl(\DateTime $nextControl = null)
    {
        $this->nextControl = $nextControl;

        return $this;
    }
    /**
     * Gets nextControl.
     *
     * @return \DateTime
     */
    public function getNextControl()
    {
        return $this->nextControl ? $this->nextControl->format('Y-m-d') : $this->nextControl;
    }
    /**
     * Add tag
     *
     * @param \AppBundle\Entity\Core\Tagg $tag
     *
     * @return AbstractControl
     */
    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;
    }
}
