using Orleans;
using static Managing.Common.Enums;

namespace Managing.Application.Abstractions.Grains;

/// <summary>
/// State model for Platform Summary Grain
/// </summary>
[GenerateSerializer]
public class PlatformSummaryGrainState
{
    [Id(0)]
    public DateTime LastUpdated { get; set; }
    
    [Id(1)]
    public DateTime LastSnapshot { get; set; }
    
    [Id(2)]
    public bool HasPendingChanges { get; set; }
    
    // Current metrics
    [Id(3)]
    public int TotalAgents { get; set; }
    
    [Id(4)]
    public int TotalActiveStrategies { get; set; }
    
    [Id(5)]
    public decimal TotalPlatformPnL { get; set; }
    
    [Id(6)]
    public decimal TotalPlatformVolume { get; set; }
    
    [Id(7)]
    public decimal TotalOpenInterest { get; set; }
    
    [Id(8)]
    public int TotalPositionCount { get; set; }
    
    // 24-hour ago values (for comparison)
    [Id(9)]
    public int TotalAgents24hAgo { get; set; }
    
    [Id(10)]
    public int TotalActiveStrategies24hAgo { get; set; }
    
    [Id(11)]
    public decimal TotalPlatformPnL24hAgo { get; set; }
    
    [Id(12)]
    public decimal TotalPlatformVolume24hAgo { get; set; }
    
    [Id(13)]
    public decimal TotalOpenInterest24hAgo { get; set; }
    
    [Id(14)]
    public int TotalPositionCount24hAgo { get; set; }
    
    // Historical snapshots
    [Id(15)]
    public List<HourlySnapshot> HourlySnapshots { get; set; } = new();
    
    [Id(16)]
    public List<DailySnapshot> DailySnapshots { get; set; } = new();
    
    // Volume breakdown by asset
    [Id(17)]
    public Dictionary<Ticker, decimal> VolumeByAsset { get; set; } = new();
    
    // Position count breakdown
    [Id(18)]
    public Dictionary<Ticker, int> PositionCountByAsset { get; set; } = new();
    
    [Id(19)]
    public Dictionary<TradeDirection, int> PositionCountByDirection { get; set; } = new();
}

/// <summary>
/// Hourly snapshot of platform metrics
/// </summary>
[GenerateSerializer]
public class HourlySnapshot
{
    [Id(0)]
    public DateTime Timestamp { get; set; }
    
    [Id(1)]
    public int TotalAgents { get; set; }
    
    [Id(2)]
    public int TotalStrategies { get; set; }
    
    [Id(3)]
    public decimal TotalVolume { get; set; }
    
    [Id(4)]
    public decimal TotalPnL { get; set; }
    
    [Id(5)]
    public decimal TotalOpenInterest { get; set; }
    
    [Id(6)]
    public int TotalPositionCount { get; set; }
}

/// <summary>
/// Daily snapshot of platform metrics
/// </summary>
[GenerateSerializer]
public class DailySnapshot
{
    [Id(0)]
    public DateTime Date { get; set; }
    
    [Id(1)]
    public int TotalAgents { get; set; }
    
    [Id(2)]
    public int TotalStrategies { get; set; }
    
    [Id(3)]
    public decimal TotalVolume { get; set; }
    
    [Id(4)]
    public decimal TotalPnL { get; set; }
    
    [Id(5)]
    public decimal TotalOpenInterest { get; set; }
    
    [Id(6)]
    public int TotalPositionCount { get; set; }
}


