using Predictalytics.Domain.Enums;

namespace Predictalytics.Domain.Entities;

/// <summary>
/// Represents a trader on a prediction market platform.
/// Identity is composite: PlatformType + PlatformUserId (e.g. wallet address on Polymarket).
/// </summary>
public class Trader
{
    public int Id { get; set; }

    /// <summary>The platform this trader belongs to.</summary>
    public PlatformType Platform { get; set; }

    /// <summary>Platform-specific user identifier (e.g. Ethereum wallet address for Polymarket).</summary>
    public string PlatformUserId { get; set; } = string.Empty;

    /// <summary>Display name / alias (can be auto-discovered or manually set).</summary>
    public string DisplayName { get; set; } = string.Empty;

    /// <summary>Optional notes about the trader.</summary>
    public string? Notes { get; set; }

    /// <summary>Whether this trader was auto-discovered or manually added.</summary>
    public bool IsAutoDiscovered { get; set; }

    /// <summary>Current tier classification.</summary>
    public TraderTier Tier { get; set; } = TraderTier.Unknown;

    /// <summary>Classified strategy type from deep-dive analysis.</summary>
    public StrategyType Strategy { get; set; } = StrategyType.Unknown;

    /// <summary>Whether the trader shows bot-like behavior.</summary>
    public bool IsSuspectedBot { get; set; }

    /// <summary>Qualification status for copy-trading master.</summary>
    public MasterStatus MasterStatus { get; set; } = MasterStatus.None;

    /// <summary>Manual priority override (null = use calculated score).</summary>
    public int? ManualPriorityOverride { get; set; }

    /// <summary>When this trader was first tracked.</summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>When data was last polled for this trader.</summary>
    public DateTime? LastPolledAt { get; set; }

    /// <summary>When the trader's trade history was last fully synced. Used for cooldown.</summary>
    public DateTime? LastTradesUpdatedAt { get; set; }

    /// <summary>Whether the initial full historical trade import is complete.</summary>
    public bool IsInitialImportComplete { get; set; }

    /// <summary>When the API first returned an error (e.g. 404 for deleted account).</summary>
    public DateTime? LastApiErrorAt { get; set; }

    /// <summary>Total estimated PnL across all resolved markets.</summary>
    public decimal TotalPnl { get; set; }

    /// <summary>Win rate as a percentage (0-100).</summary>
    public decimal WinRate { get; set; }

    /// <summary>Defines how this trader's data is ingested (based on activity level).</summary>
    public IngestMode IngestMode { get; set; } = IngestMode.Full;

    /// <summary>AI-generated strategy summary based on trade history.</summary>
    public string? AiStrategySummary { get; set; }

    /// <summary>When the AI strategy summary was last updated.</summary>
    public DateTime? AiStrategyUpdatedAt { get; set; }

    /// <summary>When the TraderAnalyticsWorker last performed a deep dive on this trader.</summary>
    public DateTime? LastAnalyzedAt { get; set; }

    /// <summary>Total number of trades tracked.</summary>
    public int TotalTrades { get; set; }

    // Navigation properties
    public ICollection<Trade> Trades { get; set; } = new List<Trade>();
    public TraderScore? CurrentScore { get; set; }
    public virtual TraderAnalytics? Analytics { get; set; }
    public ICollection<WatchlistEntry> WatchlistEntries { get; set; } = new List<WatchlistEntry>();
    public ICollection<TraderPosition> Positions { get; set; } = new List<TraderPosition>();
    public ICollection<TraderCategoryPerformance> CategoryPerformances { get; set; } = new List<TraderCategoryPerformance>();
    public ICollection<TraderTrait> Traits { get; set; } = new List<TraderTrait>();
}
