<?php

namespace Lc\SovBundle\Model\Site;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Model\Setting\SiteSettingInterface;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasTrait;

abstract class SiteModel implements SiteInterface, EntityInterface, DevAliasInterface
{
    use DevAliasTrait;

    /**
     * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Setting\SiteSettingInterface", mappedBy="site", orphanRemoval=true, cascade={"persist"}, fetch="EAGER")
     */
    protected $settings;

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

    /**
     * @return Collection|SiteSettingInterface[]
     */
    public function getSettings(): Collection
    {
        return $this->settings;
    }

    public function addSetting(SiteSettingInterface $setting): self
    {
        if (!$this->settings->contains($setting)) {
            $this->settings[] = $setting;
            $setting->setSite($this);
        }

        return $this;
    }

    public function removeSetting(SiteSettingInterface $setting): self
    {
        if ($this->settings->contains($setting)) {
            $this->settings->removeElement($setting);
            // set the owning side to null (unless already changed)
            if ($setting->getSite() === $this) {
                $setting->setSite(null);
            }
        }

        return $this;
    }

}
