using SoulstormReplayReader.Core.Enums;
using SoulstormReplayReader.Core.Models;

namespace SoulstormReplayReader.Core.Domain.Player;

public sealed class PlayerModel
{
    public static readonly PlayerModel Empty = new();

    public PlayerBugChecker BugChecker = null;

    public int Id { get; set; }
    public string Name { get; set; }
    public int RawType { get; set; }
    public string RawRace { get; set; }
    public int Team { get; set; }

    public ColorScheme ColorScheme { get; set; }
    public ReplayImage Banner { get; set; }
    public ReplayImage Badge { get; set; }

    public ReplayPlayerType ResolvedType => RawType switch
    {
        _ when Name is null && RawRace is null => ReplayPlayerType.EmptySlot,
        0 => ReplayPlayerType.Host,
        1 => ReplayPlayerType.Computer,
        2 => ReplayPlayerType.Player,
        3 => ReplayPlayerType.Computer,
        4 => ReplayPlayerType.Spectator,
        7 => ReplayPlayerType.EmptySlot,
        11 => ReplayPlayerType.Computer,
        _ => ReplayPlayerType.EmptySlot
    };

    public RaceEnum Race => RawRace?.ToLowerInvariant() switch
    {
        "space_marine_race" => RaceEnum.SpaceMarines,
        "ork_race" => RaceEnum.Orks,
        "eldar_race" => RaceEnum.Eldar,
        "chaos_marine_race" => RaceEnum.ChaosSpaceMarines,
        "dark_eldar_race" => RaceEnum.DarkEldar,
        "necron_race" => RaceEnum.Necrons,
        "sisters_race" => RaceEnum.SistersOfBattle,
        "tau_race" => RaceEnum.Tau,
        "guard_race" => RaceEnum.ImperialGuard,
        _ => RaceEnum.Unknown
    };

    public string RaceName => RawRace[..^5].Replace('_', ' ');

    public string NameTrimNewLines => Name.Replace("\t", "").Split('\r', '\n')[0];

    public bool IsHost => ResolvedType is ReplayPlayerType.Host;
    public bool IsActive => ResolvedType is ReplayPlayerType.Player or ReplayPlayerType.Host or ReplayPlayerType.Computer;
    public bool IsSpectator => ResolvedType is ReplayPlayerType.Spectator;
    public bool IsEmpty => string.IsNullOrEmpty(Name) || ResolvedType is ReplayPlayerType.EmptySlot;
}