<?php

namespace NPS\Entity;

use Doctrine\ORM\Mapping as ORM;
use NPS\Entity\UserEntity;
use NPS\Entity\KnowledgeBaseEntity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Consultation entity
 * @author Lukas Korinek
 * @ORM\Entity
 * @ORM\Table(name="`consultation`")
 */
class ConsultationEntity implements IEntity
{
    use TIdProperty;
    use TCreate;

    /**
     * @ORM\Column(type="datetime", name="date_started", nullable=false)
     * @var DateTime
     */
    public $dateStarted;

    /**
     * @ORM\Column(type="datetime", name="date_ended", nullable=true)
     * @var DateTime
     */
    public $dateEnded;

    /**
     * @ORM\Column(type="integer", name="questions_answered", nullable=false)
     * @var int
     */
    public $questionsAnswered;

    /**
     * @ORM\ManyToOne(targetEntity="UserEntity")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true)
     * @var UserEntity
     */
    public $user;

    /**
     * @ORM\ManyToOne(targetEntity="KnowledgeBaseEntity")
     * @ORM\JoinColumn(name="base_id", referencedColumnName="id", nullable=false)
     * @var KnowledgeBaseEntity
     */
    public $base;

    /**
     * @ORM\Column(type="boolean", name="flagged", nullable=false)
     * @var bool
     */
    public $flagged;

    /**
     * Internal state
     * @ORM\Column(type="text", name="state", nullable=false)
     * @var string
     */
    public $state;

    /**
     * @ORM\OneToMany(targetEntity="ConsultationAnswerEntity", mappedBy="consultation", cascade={"persist"})
     * @var ArrayCollection
     */
    public $answers;

    public function __construct()
    {
        $this->dateStarted = new \DateTime();
        $this->answers = new ArrayCollection();
        $this->flagged = false;
        $this->questionsAnswered = 0;
    }

}

