using Predictalytics.Domain.Enums;

namespace Predictalytics.Domain.Entities;

/// <summary>
/// Represents a prediction market (event/question).
/// </summary>
public class Market
{
    public int Id { get; set; }

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

    /// <summary>The Event this market belongs to.</summary>
    public int EventId { get; set; }
    public virtual Event Event { get; set; } = null!;

    /// <summary>Platform-specific numeric market identifier.</summary>
    public long PlatformMarketId { get; set; }

    /// <summary>Platform-specific blockchain market identifier (conditionId on Polymarket).</summary>
    public string ConditionId { get; set; } = string.Empty;

    /// <summary>Smart contract question ID.</summary>
    public string QuestionId { get; set; } = string.Empty;

    /// <summary>URL-friendly slug for the market.</summary>
    public string MarketSlug { get; set; } = string.Empty;

    /// <summary>Detailed market description / resolution criteria.</summary>
    public string? Description { get; set; }

    /// <summary>Market image URL.</summary>
    public string? ImageUrl { get; set; }

    /// <summary>The question being predicted.</summary>
    public string Question { get; set; } = string.Empty;

    /// <summary>Category / tag (e.g. "Politics", "Crypto", "Sports").</summary>
    public MarketCategory Category { get; set; }

    /// <summary>Subcategory (e.g. "Basketball", "Elections", "Bitcoin").</summary>
    public string Subcategory { get; set; } = string.Empty;

    /// <summary>Current total volume traded.</summary>
    public decimal Volume { get; set; }

    /// <summary>Current 24h volume.</summary>
    public decimal Volume24h { get; set; }

    /// <summary>Current liquidity.</summary>
    public decimal Liquidity { get; set; }

    /// <summary>The time when trading opened for this market.</summary>
    public DateTime? StartDate { get; set; }

    /// <summary>When the market closes / resolves.</summary>
    public DateTime? EndDate { get; set; }
    public DateTime? ClosedAt { get; set; }

    /// <summary>Whether the market has been resolved.</summary>
    public bool IsResolved { get; set; }

    /// <summary>Resolution outcome (if resolved).</summary>
    public string? ResolutionOutcome { get; set; }
    
    public decimal FeeRateBps { get; set; }
    public bool IsNegRisk { get; set; }

    /// <summary>When this market was created on the platform.</summary>
    public DateTime CreatedAt { get; set; }

    /// <summary>When this record was first saved to our database.</summary>
    public DateTime DbCreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>Last time market data was refreshed.</summary>
    public DateTime? LastUpdatedAt { get; set; }

    /// <summary>Last time market trades were polled for trader discovery.</summary>
    public DateTime? LastTradesUpdatedAt { get; set; }

    // Navigation
    public ICollection<MarketOutcome> Outcomes { get; set; } = new List<MarketOutcome>();
    public virtual MarketAnalytics? Analytics { get; set; }
}
