using Xunit;
using KArtSell.Host.Features.ShadowRun;

namespace KArtSell.Integration.Tests;

/// <summary>
/// Tests for shadow run request validation.
/// </summary>
public sealed class InitiateShadowRunTests
{
    [Fact]
    public void Validator_ValidRequest_Passes()
    {
        // Arrange
        var validator = new InitiateShadowRunValidator();
        var request = new InitiateShadowRunRequest
        {
            ModelId = Guid.NewGuid(),
            WindowStart = new DateOnly(2024, 1, 2),
            WindowEnd = new DateOnly(2026, 8, 2),
            PhaseFilter = "All"
        };

        // Act
        var result = validator.Validate(request);

        // Assert
        Assert.True(result.IsValid);
    }

    [Fact]
    public void Validator_WindowTooShort_Rejects()
    {
        // Arrange
        var validator = new InitiateShadowRunValidator();
        var request = new InitiateShadowRunRequest
        {
            ModelId = Guid.NewGuid(),
            WindowStart = new DateOnly(2024, 1, 2),
            WindowEnd = new DateOnly(2024, 1, 3),  // Only 1 day
            PhaseFilter = "All"
        };

        // Act
        var result = validator.Validate(request);

        // Assert
        Assert.False(result.IsValid);
        Assert.NotEmpty(result.Errors);
    }

    [Fact]
    public void Validator_EmptyModelId_Rejects()
    {
        // Arrange
        var validator = new InitiateShadowRunValidator();
        var request = new InitiateShadowRunRequest
        {
            ModelId = Guid.Empty,
            WindowStart = new DateOnly(2024, 1, 2),
            WindowEnd = new DateOnly(2026, 8, 2),
            PhaseFilter = "All"
        };

        // Act
        var result = validator.Validate(request);

        // Assert
        Assert.False(result.IsValid);
    }

    [Fact]
    public void Validator_InvalidPhaseFilter_Rejects()
    {
        // Arrange
        var validator = new InitiateShadowRunValidator();
        var request = new InitiateShadowRunRequest
        {
            ModelId = Guid.NewGuid(),
            WindowStart = new DateOnly(2024, 1, 2),
            WindowEnd = new DateOnly(2026, 8, 2),
            PhaseFilter = "InvalidPhase"
        };

        // Act
        var result = validator.Validate(request);

        // Assert
        Assert.False(result.IsValid);
    }

    [Theory]
    [InlineData("All")]
    [InlineData("BullMarket")]
    [InlineData("BearMarket")]
    [InlineData("Sideways")]
    [InlineData("HighVolatility")]
    public void Validator_ValidPhaseFilters_Pass(string phase)
    {
        // Arrange
        var validator = new InitiateShadowRunValidator();
        var request = new InitiateShadowRunRequest
        {
            ModelId = Guid.NewGuid(),
            WindowStart = new DateOnly(2024, 1, 2),
            WindowEnd = new DateOnly(2026, 8, 2),
            PhaseFilter = phase
        };

        // Act
        var result = validator.Validate(request);

        // Assert
        Assert.True(result.IsValid);
    }
}
