<?php

namespace App\Entity;

use App\Repository\CostingRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=CostingRepository::class)
 */
class Costing
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="text")
     */
    private $name;

    /**
     * @ORM\Column(type="string", length=16, unique=true)
     */
    private $code;

    /**
     * @ORM\ManyToOne(targetEntity=Accelerator::class, inversedBy="costings")
     * @ORM\JoinColumn(nullable=false)
     */
    private $accelerator;

    /**
     * @ORM\OneToMany(targetEntity=ActivityPTA::class, mappedBy="costing")
     */
    private $activities;

    /**
     * @ORM\ManyToMany(targetEntity=Ministry::class)
     */
    private $ministries;

    /**
     * @ORM\ManyToMany(targetEntity=Goal::class)
     */
    //, inversedBy="costings"
    private $goals;


    public function __construct()
    {
        $this->activities = new ArrayCollection();
        $this->ministries = new ArrayCollection();
        $this->goals = new ArrayCollection();
    }

    public function __toString()
    {
        return $this->getCode() . ' - ' . $this->getName();
    }

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

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getCode(): ?string
    {
        return $this->code;
    }

    public function setCode(string $code): self
    {
        $this->code = $code;

        return $this;
    }

    public function getAccelerator(): ?Accelerator
    {
        return $this->accelerator;
    }

    public function setAccelerator(?Accelerator $accelerator): self
    {
        $this->accelerator = $accelerator;

        return $this;
    }

    /**
     * @return Collection|ActivityPTA[]
     */
    public function getActivities(): Collection
    {
        return $this->activities;
    }

    public function addActivity(ActivityPTA $activity): self
    {
        if (!$this->activities->contains($activity)) {
            $this->activities[] = $activity;
            $activity->setCosting($this);
        }

        return $this;
    }

    public function removeActivity(ActivityPTA $activity): self
    {
        if ($this->activities->contains($activity)) {
            $this->activities->removeElement($activity);
            // set the owning side to null (unless already changed)
            if ($activity->getCosting() === $this) {
                $activity->setCosting(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Ministry[]
     */
    public function getMinistries(): Collection
    {
        return $this->ministries;
    }

    public function addMinistry(Ministry $ministry): self
    {
        if (!$this->ministries->contains($ministry)) {
            $this->ministries[] = $ministry;
        }

        return $this;
    }

    public function removeMinistry(Ministry $ministry): self
    {
        if ($this->ministries->contains($ministry)) {
            $this->ministries->removeElement($ministry);
        }

        return $this;
    }

    /**
     * @return Collection|Goal[]
     */
    public function getGoals(): Collection
    {
        return $this->goals;
    }

    public function addGoal(Goal $goal): self
    {
        if (!$this->goals->contains($goal)) {
            $this->goals[] = $goal;
        }

        return $this;
    }

    public function removeGoal(Goal $goal): self
    {
        if ($this->goals->contains($goal)) {
            $this->goals->removeElement($goal);
        }

        return $this;
    }
}
