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 NetPnL { get; set; }

    [Id(7)] public decimal TotalPlatformVolume { get; set; }

    [Id(8)] public decimal OpenInterest { get; set; }

    [Id(9)] public int TotalLifetimePositionCount { get; set; }

    [Id(10)] public decimal TotalPlatformFees { get; set; }

    // Historical snapshots
    [Id(11)] public List<DailySnapshot> DailySnapshots { get; set; } = new();

    // Volume breakdown by asset
    [Id(12)] public Dictionary<Ticker, decimal> VolumeByAsset { get; set; } = new();

    // Position count breakdown
    [Id(13)] public Dictionary<Ticker, int> PositionCountByAsset { get; set; } = new();

    [Id(14)] public Dictionary<TradeDirection, int> PositionCountByDirection { get; set; } = new();

    // Flag to track if volume has been updated by events (not from bot strategies)
    [Id(15)] public bool VolumeUpdatedByEvents { 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 NetPnL { get; set; }

    [Id(6)] public decimal TotalOpenInterest { get; set; }

    [Id(7)] public int TotalLifetimePositionCount { get; set; }

    [Id(8)] public int TotalPlatformFees { get; set; }
}