<?php declare(strict_types=1);
/*
 * This file is part of the SplendidBear Websites' projects.
 *
 * Copyright (c) 2019 @ www.splendidbear.org
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace App\Entity;

use App\Repository\GridRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;

/**
 * Class Grid
 *
 * @package  App\Entity
 * @author   Lang <https://www.splendidbear.org>
 * @category Class
 * @license  https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
 * @link     www.splendidbear.org
 * @since    2019. 10. 27.
 */
#[Entity(repositoryClass: GridRepository::class)]
class Grid
{
    #[Id, GeneratedValue, Column]
    public private(set) ?int $id = null;

    #[OneToOne(inversedBy: 'grid', cascade: ['persist'])]
    public ?PlayedGame $playedGame = null;

    #[OneToMany(targetEntity: GridRow::class, mappedBy: 'grid', cascade: ['persist'])]
    #[JoinColumn(name: 'grid_row', referencedColumnName: 'id', onDelete: 'CASCADE')]
    public private(set) Collection $gridRow;


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

    public function addGridRow(GridRow $gridRow): void
    {
        $this->gridRow->add($gridRow);
        $gridRow->grid = $this;
    }

    public function removeGridRow(GridRow $gridRow): void
    {
        $this->gridRow->removeElement($gridRow);
    }
}
