<?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\PlayedGameRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
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\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
use Symfony\Component\Uid\Uuid;

/**
 * Class PlayedGame
 *
 * @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: PlayedGameRepository::class)]
class PlayedGame
{
    #[Id, GeneratedValue, Column]
    public private(set) ?int $id = null;

    #[Column(type: 'uuid', unique: true)]
    public ?Uuid $uuid = null;

    #[Column(length: 50)]
    public ?string $gameAssoc = null;

    #[Column(length: 5, nullable: true)]
    public ?int $redPoints = null;

    #[Column(length: 5, nullable: true)]
    public ?int $bluePoints = null;

    #[Column(nullable: true)]
    public ?bool $redExplodedBomb = null;

    #[Column(nullable: true)]
    public ?bool $blueExplodedBomb = null;

    #[Column(length: 7, nullable: true)]
    public ?string $resign = null;

    #[Column(nullable: true)]
    public ?float $redBonusPoints = null;

    #[Column(nullable: true)]
    public ?float $blueBonusPoints = null;

    #[Column(nullable: true)]
    public ?array $redBonusStats = null;

    #[Column(nullable: true)]
    public ?array $blueBonusStats = null;

    #[Column(type: Types::DATETIME_MUTABLE, nullable: true)]
    public ?DateTime $created = null;

    #[Column(type: Types::DATETIME_MUTABLE, nullable: true)]
    public ?DateTime $updated = null;

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

    #[ManyToOne]
    #[JoinColumn(name: 'red_id', referencedColumnName: 'id', nullable: true)]
    public ?User $red = null;

    #[ManyToOne]
    #[JoinColumn(name: 'red_anon', referencedColumnName: 'id', nullable: true)]
    public ?Gamer $redAnon = null;

    #[ManyToOne]
    #[JoinColumn(name: 'blue_id', referencedColumnName: 'id', nullable: true)]
    public ?User $blue = null;

    #[ManyToOne]
    #[JoinColumn(name: 'blue_anon', referencedColumnName: 'id', nullable: true)]
    public ?Gamer $blueAnon = null;

    #[OneToMany(mappedBy: 'playedGame', targetEntity: Step::class)]
    public private(set) Collection $steps;


    public function __construct()
    {
        $this->steps = new ArrayCollection();
        $this->uuid = Uuid::v4();
    }
}
