using Managing.Domain.Strategies;
using Orleans;

namespace Managing.Domain.Scenarios;

/// <summary>
/// Lightweight scenario class for Orleans serialization
/// Contains only the essential properties needed for backtesting
/// </summary>
[GenerateSerializer]
public class LightScenario
{
    public LightScenario(string name, int? loopbackPeriod = 1)
    {
        Name = name;
        Indicators = new List<LightIndicator>();
        LoopbackPeriod = loopbackPeriod;
    }

    [Id(0)] public string Name { get; set; }

    [Id(1)] public List<LightIndicator> Indicators { get; set; }

    [Id(2)] public int? LoopbackPeriod { get; set; }

    /// <summary>
    /// Converts a full Scenario to a LightScenario
    /// </summary>
    public static LightScenario FromScenario(Scenario scenario)
    {
        var lightScenario = new LightScenario(scenario.Name, scenario.LoopbackPeriod)
        {
            Indicators = scenario.Indicators?.Select(LightIndicator.BaseToLight).ToList() ??
                         new List<LightIndicator>()
        };
        return lightScenario;
    }

    /// <summary>
    /// Converts a LightScenario back to a full Scenario
    /// </summary>
    public Scenario ToScenario()
    {
        var scenario = new Scenario(Name, LoopbackPeriod)
        {
            Indicators = Indicators?.Select(li => li.LightToBase()).ToList()
        };
        return scenario;
    }
}