<?php

namespace App\Entity\Campaign;

use App\Entity\Campaign;
use App\Entity\Traits\TimestampableTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity()
 * @ORM\Table(name="campaign_level")
 */
class Level
{
    use TimestampableTrait;

    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", nullable=false)
     * @Assert\NotBlank()
     */
    private $title;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $options;

    /**
     * @ORM\OneToMany(targetEntity="\App\Entity\Campaign", mappedBy="level")
     */
    private $campaigns;

    /**
     * @ORM\Column(type="integer", nullable=true, options={"default" : 0})
     * @Assert\NotBlank()
     */
    private $linkTarget;

    /**
     * @ORM\Column(type="integer", nullable=true, options={"default" : 0})
     * @Assert\NotBlank()
     */
    private $guestPosts;

    /**
     * @ORM\Column(type="string", length=7, nullable=true)
     */
    private $colour;

    public function __construct()
    {
        $this->campaigns = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getOptions()
    {
        return json_decode($this->options, true);
    }

    public function setOptions(?string $options): self
    {
        $this->options = $options;

        return $this;
    }

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

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

//    /**
//     * @return Collection|Campaign[]
//     */
//    public function getCampaigns(): Collection
//    {
//        return $this->campaigns;
//    }

    public function addCampaign(Campaign $campaign): self
    {
        if (!$this->campaigns->contains($campaign)) {
            $this->campaigns[] = $campaign;
            $campaign->setLevel($this);
        }

        return $this;
    }

    public function removeCampaign(Campaign $campaign): self
    {
        if ($this->campaigns->contains($campaign)) {
            $this->campaigns->removeElement($campaign);
            // set the owning side to null (unless already changed)
            if ($campaign->getLevel() === $this) {
                $campaign->setLevel(null);
            }
        }

        return $this;
    }

    public function getLinkTarget(): ?int
    {
        return $this->linkTarget;
    }

    public function setLinkTarget(int $linkTarget): self
    {
        $this->linkTarget = $linkTarget;

        return $this;
    }

    public function getGuestPosts(): ?int
    {
        return $this->guestPosts;
    }

    public function setGuestPosts(int $guestPosts): self
    {
        $this->guestPosts = $guestPosts;

        return $this;
    }

    public function getColour(): ?string
    {
        return $this->colour;
    }

    public function setColour(?string $colour): self
    {
        $this->colour = $colour;

        return $this;
    }
}
