using Minint.Core.Models;
using Minint.Core.Services.Impl;

namespace Minint.Tests;

public class FloodFillTests
{
    private readonly FloodFillService _fill = new();

    [Fact]
    public void Fill_EmptyLayer_FillsAll()
    {
        var layer = new MinintLayer("L1", 9); // 3x3, all zeros
        _fill.Fill(layer, 0, 0, 1, 3, 3);

        Assert.All(layer.Pixels, px => Assert.Equal(1, px));
    }

    [Fact]
    public void Fill_SameColor_NoOp()
    {
        var layer = new MinintLayer("L1", 4);
        Array.Fill(layer.Pixels, 2);
        _fill.Fill(layer, 0, 0, 2, 2, 2);

        Assert.All(layer.Pixels, px => Assert.Equal(2, px));
    }

    [Fact]
    public void Fill_Bounded_DoesNotCrossBorder()
    {
        // 3x3 grid with a wall:
        // 0 0 0
        // 1 1 1
        // 0 0 0
        var layer = new MinintLayer("L1", 9);
        layer.Pixels[3] = 1; // (0,1)
        layer.Pixels[4] = 1; // (1,1)
        layer.Pixels[5] = 1; // (2,1)

        _fill.Fill(layer, 0, 0, 2, 3, 3);

        // Top row should be filled
        Assert.Equal(2, layer.Pixels[0]);
        Assert.Equal(2, layer.Pixels[1]);
        Assert.Equal(2, layer.Pixels[2]);
        // Wall untouched
        Assert.Equal(1, layer.Pixels[3]);
        // Bottom row untouched (blocked by wall)
        Assert.Equal(0, layer.Pixels[6]);
    }
}
