using Predictalytics.Domain.Enums;

namespace Predictalytics.Application.DTOs;

public record TraderDto(
    int Id,
    string Platform,
    string PlatformUserId,
    string DisplayName,
    string Tier,
    string Strategy,
    decimal CombinedScore,
    decimal CopytradingScore,
    decimal CopytradingQualityScore,
    decimal CopytradingCopyabilityScore,
    decimal WinRate,
    decimal TotalPnl,
    int TotalTrades,
    int Trades30d,
    decimal PnL30d,
    decimal WinRate30d,
    decimal EstimatedBankroll,
    bool IsOnWatchlist,
    bool IsSuspectedBot,
    DateTime? LastPolledAt,
    List<string>? Traits
);

public record TraderDetailDto(
    int Id,
    string Platform,
    string PlatformUserId,
    string DisplayName,
    string? Notes,
    string Tier,
    string Strategy,
    bool IsSuspectedBot,
    int? ManualPriorityOverride,
    decimal WinRate,
    decimal TotalPnl,
    int TotalTrades,
    int Trades30d,
    decimal PnL30d,
    decimal WinRate30d,
    decimal PnL7d,
    decimal WinRate7d,
    decimal PnL24h,
    decimal WinRate24h,
    decimal EstimatedBankroll,
    decimal CurrentBalance,
    decimal ActivityScore,
    decimal QualityScore,
    decimal VolumeScore,
    decimal TimingScore,
    decimal CombinedScore,
    decimal CopytradingScore,
    decimal CopytradingQualityScore,
    decimal CopytradingCopyabilityScore,
    
    // Market Return Metrics
    decimal MedianWinReturnPct,
    decimal AvgWinReturnPct,
    decimal MedianLossReturnPct,
    decimal AvgLossReturnPct,
    decimal? ProfitFactor,
    
    int Rank,
    bool IsOnWatchlist,
    DateTime CreatedAt,
    DateTime? LastPolledAt,
    string? AiStrategySummary,
    IReadOnlyList<TradeDto> RecentTrades,
    IReadOnlyList<TraderCategoryPerformanceDto> CategoryPerformances,
    IReadOnlyList<TraderTraitDto> Traits
);

public record TraderTraitDto(
    string Trait,
    decimal Value
);

public record TraderCategoryPerformanceDto(
    string Category,
    decimal TotalVolume,
    decimal TotalPnL,
    int TotalTrades,
    int WinningTrades,
    decimal WinRate,
    decimal AvgReturnPct
);

public record TraderPositionDto(
    string MarketId,
    string? MarketName,
    string? Category,
    string? OutcomeToken,
    decimal SharesHeld,
    decimal AvgCost,
    decimal RealizedPnl,
    decimal UnrealizedPnl,
    decimal CurrentPrice,
    DateTime? LastTradeExecutedAt
);

public record TraderWindowMetricsDto(
    DateTime WindowStart,
    DateTime WindowEnd,
    int ClosedMarkets,
    decimal WinRate,
    decimal AvgReturnPct,
    decimal MedianWinReturnPct,
    decimal MedianLossReturnPct,
    decimal? ProfitFactor
);

public record TraderProfileDto(
    int Id,
    string DisplayName,
    MasterStatus MasterStatus,
    decimal MedianHoldDurationHours,
    decimal P50PositionSize,
    decimal P90PositionSize,
    decimal TradesPerWeek,
    decimal MedianMarketVolumeUsd,
    decimal MedianPostFillDriftPct,
    decimal NetEdgeAfterFeesPct,
    string? PriceBandProfileJson,
    IReadOnlyList<TraderWindowMetricsDto> WindowMetrics
);

public record TraderCorrelationDto(
    int TraderAId,
    int TraderBId,
    int CommonMarketsCount,
    int SameDirectionMarketsCount,
    decimal IntersectionRatioA,
    decimal IntersectionRatioB,
    decimal AgreementRatio
);
