<?php

namespace App\Model\Entities\Components\News;

use App\Model\Entities\BaseRecord;
use App\Model\Entities\Localization\Language;
use App\Model\Entities\Security\User;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="news")
 */
class News extends BaseRecord
{
    const CREATED = 'created';
    const PUBLISHED = 'published';

    /**
     * @var Language
     * @ORM\ManyToOne(targetEntity="App\Model\Entities\Localization\Language")
     */
    protected $language;

    /**
     * @var NewsContainer
     * @ORM\ManyToOne(targetEntity="NewsContainer")
     */
    protected $container;

    /**
     * @ORM\Column(type="string")
     */
    protected $title;

    /**
     * @ORM\Column(type="string")
     */
    protected $description;

    /**
     * @ORM\Column(type="text")
     */
    protected $content;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    protected $publishedAt;

    /**
     * @var ArrayCollection
     * @ORM\ManyToMany(targetEntity="App\Model\Entities\Image")
     */
    protected $images;

    /**
     * @var ArrayCollection
     * @ORM\ManyToMany(targetEntity="App\Model\Entities\Reference")
     */
    protected $references;

    public function __construct(User $createdBy)
    {
        parent::__construct($createdBy);

        $this->images = new ArrayCollection();
        $this->references = new ArrayCollection();

        $this->setState(self::CREATED);
    }

    /**
     * @return Language
     */
    public function getLanguage() : Language
    {
        return $this->language;
    }

    /**
     * @param Language $language
     */
    public function setLanguage(Language $language)
    {
        $this->language = $language;
    }

    /**
     * @return NewsContainer
     */
    public function getContainer() : NewsContainer
    {
        return $this->container;
    }

    /**
     * @param NewsContainer $container
     */
    public function setContainer($container)
    {
        $this->container = $container;
    }

    /**
     * @return string
     */
    public function getTitle() : string
    {
        return $this->title;
    }

    /**
     * @param string $title
     */
    public function setTitle(string $title)
    {
        $this->title = $title;
    }

    /**
     * @return string
     */
    public function getDescription() : string
    {
        return $this->description;
    }

    /**
     * @param string $description
     */
    public function setDescription(string $description)
    {
        $this->description = $description;
    }

    /**
     * @return string
     */
    public function getContent() : string
    {
        return $this->content;
    }

    /**
     * @param string $content
     */
    public function setContent(string $content)
    {
        $this->content = $content;
    }

    /**
     * @return DateTime
     */
    public function getPublishedAt() : DateTime
    {
        return $this->publishedAt;
    }

    /**
     * @param DateTime $publishedAt
     */
    public function setPublishedAt(DateTime $publishedAt)
    {
        $this->publishedAt = $publishedAt;
    }

    protected function getValidStates() : array
    {
        $states =  parent::getValidStates();
        $states[] = self::CREATED;
        $states[] = self::PUBLISHED;

        return $states;
    }


}