namespace TradingBot.Models;

public class AssetStatistics
{
    public string Symbol { get; set; } = string.Empty;
    public string Name { get; set; } = string.Empty;
    
    // Trading Performance
    public int TotalTrades { get; set; }
    public int WinningTrades { get; set; }
    public int LosingTrades { get; set; }
    public decimal WinRate => TotalTrades > 0 ? (decimal)WinningTrades / TotalTrades * 100 : 0;
    
    // Financial Metrics
    public decimal TotalProfit { get; set; }
    public decimal TotalLoss { get; set; }
    public decimal NetProfit => TotalProfit - TotalLoss;
    public decimal ProfitPercentage { get; set; }
    public decimal AverageProfit => WinningTrades > 0 ? TotalProfit / WinningTrades : 0;
    public decimal AverageLoss => LosingTrades > 0 ? TotalLoss / LosingTrades : 0;
    public decimal ProfitFactor => TotalLoss > 0 ? TotalProfit / TotalLoss : TotalProfit > 0 ? decimal.MaxValue : 0;
    
    // Position Information
    public decimal CurrentPosition { get; set; }
    public decimal AverageEntryPrice { get; set; }
    public decimal CurrentPrice { get; set; }
    public decimal UnrealizedPnL => CurrentPosition > 0 && AverageEntryPrice > 0 
        ? (CurrentPrice - AverageEntryPrice) * CurrentPosition 
        : 0;
    public decimal UnrealizedPnLPercentage => AverageEntryPrice > 0 
        ? (CurrentPrice - AverageEntryPrice) / AverageEntryPrice * 100 
        : 0;
    
    // Risk Metrics
    public decimal MaxDrawdown { get; set; }
    public decimal CurrentDrawdown { get; set; }
    public decimal LargestWin { get; set; }
    public decimal LargestLoss { get; set; }
    public decimal SharpeRatio { get; set; }
    
    // Time-based Metrics
    public DateTime? FirstTradeTime { get; set; }
    public DateTime? LastTradeTime { get; set; }
    public TimeSpan TradingDuration => FirstTradeTime.HasValue && LastTradeTime.HasValue 
        ? LastTradeTime.Value - FirstTradeTime.Value 
        : TimeSpan.Zero;
    
    // Daily Statistics
    public int TradesToday { get; set; }
    public decimal ProfitToday { get; set; }
    public decimal ProfitTodayPercentage { get; set; }
    
    // Trade Details
    public List<Trade> RecentTrades { get; set; } = new();
    public List<decimal> EquityCurve { get; set; } = new();
    
    // Strategy Performance
    public Dictionary<string, int> TradesByStrategy { get; set; } = new();
    public Dictionary<string, decimal> ProfitByStrategy { get; set; } = new();
    
    // Additional Metrics
    public decimal AverageTradeSize { get; set; }
    public decimal AverageHoldingTime { get; set; } // in hours
    public int ConsecutiveWins { get; set; }
    public int ConsecutiveLosses { get; set; }
    public int MaxConsecutiveWins { get; set; }
    public int MaxConsecutiveLosses { get; set; }
}

public class PortfolioStatistics
{
    public decimal TotalBalance { get; set; }
    public decimal InitialBalance { get; set; }
    public decimal TotalProfit => TotalBalance - InitialBalance;
    public decimal TotalProfitPercentage => InitialBalance > 0 ? (TotalProfit / InitialBalance) * 100 : 0;
    
    public int TotalAssets { get; set; }
    public int ActiveAssets { get; set; }
    public int TotalTrades { get; set; }
    public decimal WinRate { get; set; }
    
    public decimal BestPerformingAssetProfit { get; set; }
    public string BestPerformingAssetSymbol { get; set; } = string.Empty;
    public decimal WorstPerformingAssetProfit { get; set; }
    public string WorstPerformingAssetSymbol { get; set; } = string.Empty;
    
    public List<AssetStatistics> AssetStatistics { get; set; } = new();
    
    public Dictionary<string, decimal> DailyProfits { get; set; } = new();
    public Dictionary<string, int> DailyTrades { get; set; } = new();
    
    public DateTime? StartDate { get; set; }
    public DateTime LastUpdateTime { get; set; } = DateTime.UtcNow;
}
