<?php declare(strict_types=1);
/**
 * This file is part of the SplendidBear Websites' projects.
 *
 * Copyright (c) 2026 @ 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\RecentBattleRepository;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;

/**
 * Class RecentBattle
 *
 * Read-only entity mapped to the recent_battles materialized view.
 * Each row represents one game from the perspective of a single user.
 *
 * @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    2026. 04. 20.
 */
#[Entity(repositoryClass: RecentBattleRepository::class, readOnly: true), Table(name: 'recent_battles')]
class RecentBattle
{
    /** Composite PK: (user_id, game_id) — mapped via the unique index. */
    #[Id, Column]
    public int $userId = 0;

    #[Id, Column]
    public int $gameId = 0;

    #[Column(name: 'uuid')]
    public string $uuid = '';

    #[Column]
    public bool $isRed = false;

    #[Column]
    public string $redName = '';

    #[Column]
    public string $blueName = '';

    #[Column(nullable: true)]
    public ?string $redAvatarPath = null;

    #[Column(nullable: true)]
    public ?string $blueAvatarPath = null;

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

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

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

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

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

    #[Column]
    public float $redBonusPoints = 0.0;

    #[Column]
    public float $blueBonusPoints = 0.0;

    #[Column(type: Types::JSON)]
    public array $redBonusStats = [];

    #[Column(type: Types::JSON)]
    public array $blueBonusStats = [];

    #[Column]
    public string $result = 'draw';

    #[Column]
    public bool $oppIsGuest = false;

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

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