using Domain.Weapons;
using Infrastructure;
using System.Xml.Linq;

namespace Domain;

public class Player : BaseEntity
{
   
    public string? Name { get; set; }
    public string? CharacterName { get; set; }
    public string? Background { get; set; }
    public int Experience { get; set; }
    public int CC { get; set; }
    public int CT { get; set; }
    public int F { get; set; }
    public int E { get; set; }
    public int AG { get; set; }
    public int INT { get; set; }
    public int PER { get; set; }
    public int FM { get; set; }
    public int SOC { get; set; }
    public int MF { get; set; }

    public ICollection<Weapon> Weapons { get; set; }

    public int Initiative()
    {
        return DiceService.RollDices(1, 10) + DiceService.Bonus(AG);
    }

    public bool TestCC()
    {
        return DiceService.RollDices(1, 100) <= CC;
    }

    public bool TestCT()
    {
        return DiceService.RollDices(1, 100) <= CT;
    }

    public bool TestF()
    {
        return DiceService.RollDices(1, 100) <= F;
    }

    public bool TestE()
    {
        return DiceService.RollDices(1, 100) <= E;
    }

    public bool TestAG()
    {
        return DiceService.RollDices(1, 100) <= AG;
    }

    public bool TestINT()
    {
        return DiceService.RollDices(1, 100) <= INT;
    }

    public bool TestPER()
    {
        return DiceService.RollDices(1, 100) <= PER;
    }

    public bool TestFM()
    {
        return DiceService.RollDices(1, 100) <= FM;
    }

    public bool TestSOC()
    {
        return DiceService.RollDices(1, 100) <= SOC;
    }

    public bool TestMF()
    {
        return DiceService.RollDices(1, 100) <= MF;
    }

    public static List<Player> LoadPlayersFromXml(string filePath)
    {
        XDocument xdoc = XDocument.Load(filePath);
        var players = from player in xdoc.Descendants("Player")
                      select new Player
                      {
                          Name = (string)player.Element("Name"),
                          CharacterName = (string)player.Element("CharacterName"),
                          Background = (string)player.Element("Background"),
                          Experience = (int)player.Element("Experience"),
                          CC = (int)player.Element("CC"),
                          CT = (int)player.Element("CT"),
                          F = (int)player.Element("F"),
                          E = (int)player.Element("E"),
                          AG = (int)player.Element("AG"),
                          INT = (int)player.Element("INT"),
                          PER = (int)player.Element("PER"),
                          FM = (int)player.Element("FM"),
                          SOC = (int)player.Element("SOC"),
                          MF = (int)player.Element("MF"),
                          CreatedDate = (DateTime)player.Element("CreatedDate"),
                          ModifiedDate = (DateTime)player.Element("ModifiedDate")
                      };

        return players.ToList();
    }
}