using LittleTown.Core.Enums;
using LittleTown.Core.Exceptions;
using LittleTown.StaticDataAcces;

namespace LittleTown.Core.Tests;

public class MatchTesting
{
    [Fact]
    public void EnforcePlayerCountInMatchCreation()
    {
        StaticDataGetter getter = new();
        var match = new Match(getter);
        match.AddPlayer("Player1");
        Assert.Throws<ArgumentOutOfRangeException>(() => { match.Init(); });

        Match match2 = new Match(getter);
        match2.AddPlayer("Player1");
        match2.AddPlayer("Player2");
        Assert.Throws<MatchConfigException>(() => match2.AddPlayer("Player2"));
        match2.Init();

        Match match3 = new Match(getter);
        match3.AddPlayer("Player1");
        match3.AddPlayer("Player2");
        match3.AddPlayer("Player3");
        match3.Init();

        Match match4 = new Match(getter);
        match4.AddPlayer("Player1");
        match4.AddPlayer("Player2");
        match4.AddPlayer("Player3");
        match4.AddPlayer("Player4");
        match4.Init();

        Match match5 = new Match(getter);
        match5.AddPlayer("Player1");
        match5.AddPlayer("Player2");
        match5.AddPlayer("Player3");
        match5.AddPlayer("Player4");
        Assert.Throws<MatchConfigException>(() => { match5.AddPlayer("Player5"); });
    }

    [Fact]
    public void TwoPlayerInitMatchTest()
    {
        StaticDataGetter getter = new();
        Match match = new Match(getter);
        match.AddPlayer("Player1");
        match.AddPlayer("Player2");
        match.Init();

        PlayerZone player1 = match.GetPlayerZone("Player1");
        PlayerZone player1_3 = match.GetPlayerZone("Player2");

        Assert.Equal(3, player1.Ressources[Enums.ResourceType.Piece]);
        player1.AddRessources(ResourceType.Piece, 1);
        Assert.Equal(3, player1_3.Ressources[Enums.ResourceType.Piece]);

        Assert.Equal(4, player1.Objectives.Count);
    }

    [Fact]
    public void MatchGetters()
    {
        StaticDataGetter getter = new();
        Match match = new Match(getter);
        match.AddPlayer("Player1");
        match.AddPlayer("Player2");
        match.Init();

        Assert.Throws<ArgumentException>(() => match.GetPlayerZone("UnknownPlayer"));
    }
}