using System.Collections.Generic;
using Xunit;
using QuantEngine.Core.Domain;

namespace QuantEngine.Core.Tests;

public class PortfolioSizerTests
{
    [Fact]
    public void CalculateTargetAllocations_WithValidScores_EnforcesCapsCorrectly()
    {
        // Arrange
        var sizer = new PortfolioSizer();
        var scores = new Dictionary<string, decimal>
        {
            { "005930", 80m },
            { "000660", 20m }
        };
        var prices = new Dictionary<string, decimal>
        {
            { "005930", 70000m },
            { "000660", 120000m }
        };
        var vols = new Dictionary<string, decimal>();

        // Act
        var packet = sizer.CalculateTargetAllocations("2026-07-24", 100000000m, 0.10m, scores, prices, vols);

        // Assert
        Assert.Equal("2026-07-24", packet.AsOfDate);
        Assert.True(packet.AllCapsSatisfied);
        Assert.Equal(10000000m, packet.ReservedCashKrw);
        Assert.Equal(2, packet.Allocations.Count);
        Assert.True(packet.Allocations[0].TargetWeightRatio <= 0.25m); // Cap enforced
    }
}
