using Managing.Application.Abstractions.Models;
using Managing.Common;

namespace Managing.Api.Models.Responses
{
    /// <summary>
    /// Summary of agent performance and activity
    /// </summary>
    public class AgentSummaryViewModel
    {
        /// <summary>
        /// AgentName of the agent
        /// </summary>
        public string AgentName { get; set; }

        /// <summary>
        /// Total profit and loss in USD
        /// </summary>
        public decimal TotalPnL { get; set; }

        /// <summary>
        /// Total return on investment as a percentage
        /// </summary>
        public decimal TotalROI { get; set; }

        /// <summary>
        /// Number of winning trades
        /// </summary>
        public int Wins { get; set; }

        /// <summary>
        /// Number of losing trades
        /// </summary>
        public int Losses { get; set; }


        /// <summary>
        /// Number of active strategies for this agent
        /// </summary>
        public int ActiveStrategiesCount { get; set; }

        /// <summary>
        /// Total volume traded by this agent in USD
        /// </summary>
        public decimal TotalVolume { get; set; }

        /// <summary>
        /// Total balance including USDC and open position values (without leverage, including PnL)
        /// </summary>
        public decimal TotalBalance { get; set; }
    }

    /// <summary>
    /// Platform-wide statistics without individual agent details
    /// </summary>
    public class PlatformSummaryViewModel
    {
        /// <summary>
        /// Total number of agents on the platform
        /// </summary>
        public required int TotalAgents { get; set; }

        /// <summary>
        /// Total number of active strategies across all agents
        /// </summary>
        public required int TotalActiveStrategies { get; set; }

        /// <summary>
        /// Total platform-wide profit and loss in USD
        /// </summary>
        public required decimal TotalPlatformPnL { get; set; }

        /// <summary>
        /// Total volume traded across all agents in USD
        /// </summary>
        public required decimal TotalPlatformVolume { get; set; }

        /// <summary>
        /// Total volume traded across all agents in the last 24 hours in USD
        /// </summary>
        public required decimal TotalPlatformVolumeLast24h { get; set; }

        /// <summary>
        /// Total open interest across all positions in USD
        /// </summary>
        public required decimal TotalOpenInterest { get; set; }

        /// <summary>
        /// Total number of open positions across all strategies
        /// </summary>
        public required int TotalPositionCount { get; set; }

        // 24-hour changes
        /// <summary>
        /// Change in agent count over the last 24 hours
        /// </summary>
        public required int AgentsChange24h { get; set; }

        /// <summary>
        /// Change in strategy count over the last 24 hours
        /// </summary>
        public required int StrategiesChange24h { get; set; }

        /// <summary>
        /// Change in PnL over the last 24 hours
        /// </summary>
        public required decimal PnLChange24h { get; set; }

        /// <summary>
        /// Change in volume over the last 24 hours
        /// </summary>
        public required decimal VolumeChange24h { get; set; }

        /// <summary>
        /// Change in open interest over the last 24 hours
        /// </summary>
        public required decimal OpenInterestChange24h { get; set; }

        /// <summary>
        /// Change in position count over the last 24 hours
        /// </summary>
        public required int PositionCountChange24h { get; set; }

        // Breakdowns
        /// <summary>
        /// Volume breakdown by asset/ticker
        /// </summary>
        public required Dictionary<Enums.Ticker, decimal> VolumeByAsset { get; set; }

        /// <summary>
        /// Position count breakdown by asset/ticker
        /// </summary>
        public required Dictionary<Enums.Ticker, int> PositionCountByAsset { get; set; }

        /// <summary>
        /// Position count breakdown by direction (Long/Short)
        /// </summary>
        public required Dictionary<Enums.TradeDirection, int> PositionCountByDirection { get; set; }

        // Metadata
        /// <summary>
        /// When the data was last updated
        /// </summary>
        public required DateTime LastUpdated { get; set; }

        /// <summary>
        /// When the last 24-hour snapshot was taken
        /// </summary>
        public required DateTime Last24HourSnapshot { get; set; }
        public List<VolumeHistoryPoint> VolumeHistory { get; internal set; }
    }

    /// <summary>
    /// Response model containing a list of agent summaries for the agent index
    /// </summary>
    public class AgentIndexViewModel
    {
        /// <summary>
        /// List of agent summaries sorted by performance
        /// </summary>
        public List<AgentSummaryViewModel> AgentSummaries { get; set; } = new List<AgentSummaryViewModel>();

        /// <summary>
        /// Time filter applied to the data
        /// </summary>
        public string TimeFilter { get; set; } = "Total";
    }
}