<?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\Dto;

use App\Entity\UserStats;

/**
 * Class ProfileStatsDto
 *
 * @package  App\Dto
 * @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.
 */
final readonly class ProfileStatsDto
{
    public function __construct(
        public int   $total,
        public int   $wins,
        public int   $losses,
        public int   $draws,
        public int   $minesHit,
        public int   $winRate,
        public int   $avgScore,
        public float $bonusPoints,
        public float $avgBonus,
        public int   $bestChain,
        public int   $blindHits,
        public int   $edgeMines,
    ) {
    }

    public static function fromUserStats(?UserStats $stats): self
    {
        if ($stats === null) {
            return self::empty();
        }

        return new self(
            total: $stats->totalGames,
            wins: $stats->wins,
            losses: $stats->losses,
            draws: $stats->draws,
            minesHit: $stats->totalMines,
            winRate: $stats->getWinRate(),
            avgScore: $stats->getAvgScore(),
            bonusPoints: (float)$stats->totalBonusPoints,
            avgBonus: (float)$stats->avgBonus,
            bestChain: $stats->bestChain,
            blindHits: $stats->blindHits,
            edgeMines: $stats->edgeMines,
        );
    }

    public static function empty(): self
    {
        return new self(
            total: 0,
            wins: 0,
            losses: 0,
            draws: 0,
            minesHit: 0,
            winRate: 0,
            avgScore: 0,
            bonusPoints: 0.0,
            avgBonus: 0.0,
            bestChain: 0,
            blindHits: 0,
            edgeMines: 0,
        );
    }
}
