using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Tiles;
namespace TestBase;

public class TestCell
{
    [Theory]
    [InlineData(true, 10, 20)]
    [InlineData(false, -10, -10)]
    [InlineData(false, 10, -10)]
    [InlineData(false, -10, 10)]

    public void Test_CellConstructor(bool isValid, int x, int y)
    {
        if (!isValid)
        {
            Assert.Throws<ArgumentException>(() => new Cell(x, y));
            return;
        }

        Cell c = new Cell(x, y);
        Assert.Equal(x, c.GetX);
        Assert.Equal(y, c.GetY);
    }

    public static TheoryData<bool, int, int, Shape, Color> Data_Cell()
    {
        var data = new TheoryData<bool, int, int, Shape, Color>
        {
            {
                true,
                0,
                0,
                Shape.Round,
                Color.Red

            },
            {
                false,
                0,
                0,
                Shape.Round,
                Color.Red
            }
        };
        return data;
    }

    [Theory]
    [MemberData(nameof(Data_Cell))]
    public void Test_CellSetTile(bool except, int x, int y, Shape shape, Color color)
    {
        Tile t = new(shape, color);
        Cell c = new(x, y);

        if (!except)
        {
            c.SetTile(t);
            Assert.False(c.SetTile(t));
            return;
        }
        Assert.True(c.SetTile(t));
    }

    [Theory]
    [MemberData(nameof(Data_Cell))]
    public void Test_IsFree(bool except, int x, int y, Shape shape, Color color)
    {
        Tile t = new(shape, color);
        Cell c = new(x, y);

        if (!except)
        {
            c.SetTile(t);
            Assert.False(c.IsFree);
            return;
        }
        Assert.True(c.IsFree);
    }

    [Fact]
    public void Test_EventCell()
    {
        Cell c = new(1,1);
        Tile tile = new(Shape.Club, Color.Red);

        bool eventRaised = false;

        c.PropertyChanged += (sender, args) =>
        {
            eventRaised = true;
        };

        c.SetTile(tile);

        Assert.True(eventRaised);
    }




}

