using System.Text.Json.Serialization;

namespace Predictalytics.Infrastructure.Providers.Limitless;

public class LimitlessActiveMarketsResponse
{
    [JsonPropertyName("data")]
    public List<LimitlessMarketResponse>? Data { get; set; }

    [JsonPropertyName("totalMarketsCount")]
    public int TotalMarketsCount { get; set; }
}

public class LimitlessEventsResponse
{
    [JsonPropertyName("events")]
    public List<LimitlessEventResponse>? Events { get; set; }
}

public class LimitlessPortfolioResponse
{
    [JsonPropertyName("clob")]
    public List<LimitlessClobItem>? Clob { get; set; }

    [JsonPropertyName("amm")]
    public List<LimitlessClobItem>? Amm { get; set; }

    [JsonPropertyName("group")]
    public List<LimitlessClobItem>? Group { get; set; }
}

public class LimitlessClobItem
{
    [JsonPropertyName("market")]
    public LimitlessMarketResponse? Market { get; set; }

    [JsonPropertyName("positions")]
    public LimitlessPositionsContainer? Positions { get; set; }
}

public class LimitlessPositionsContainer
{
    [JsonPropertyName("yes")]
    public LimitlessPositionDetails? Yes { get; set; }

    [JsonPropertyName("no")]
    public LimitlessPositionDetails? No { get; set; }
}

public class LimitlessPositionDetails
{
    [JsonPropertyName("size")]
    public string? Size { get; set; } // API uses strings for numbers here

    [JsonPropertyName("fillPrice")]
    public string? FillPrice { get; set; }

    [JsonPropertyName("marketValue")]
    public string? MarketValue { get; set; }

    [JsonPropertyName("realisedPnl")]
    public string? RealisedPnl { get; set; }

    [JsonPropertyName("unrealizedPnl")]
    public string? UnrealizedPnl { get; set; }

    [JsonPropertyName("latestTrade")]
    public LimitlessTradeInfo? LatestTrade { get; set; }
}

public class LimitlessMarketResponse
{
    [JsonPropertyName("address")]
    public string? Address { get; set; }

    [JsonPropertyName("slug")]
    public string? Slug { get; set; }

    [JsonPropertyName("title")]
    public string? Title { get; set; }

    [JsonPropertyName("description")]
    public string? Description { get; set; }

    [JsonPropertyName("categories")]
    public List<string>? Categories { get; set; }

    [JsonPropertyName("imageUrl")]
    public string? ImageUrl { get; set; }

    [JsonPropertyName("expirationDate")]
    public string? ExpirationDate { get; set; }

    [JsonPropertyName("expirationTimestamp")]
    public long? ExpirationTimestamp { get; set; }

    [JsonPropertyName("active")]
    public bool Active { get; set; }

    [JsonPropertyName("closed")]
    public bool Closed { get; set; }

    [JsonPropertyName("volumeFormatted")]
    public string? VolumeFormatted { get; set; }

    [JsonPropertyName("liquidity")]
    public double? Liquidity { get; set; }

    [JsonPropertyName("prices")]
    public List<double>? Prices { get; set; }

    [JsonPropertyName("tokens")]
    public LimitlessTokens? Tokens { get; set; }
}

public class LimitlessTokens
{
    [JsonPropertyName("yes")]
    public string? Yes { get; set; }

    [JsonPropertyName("no")]
    public string? No { get; set; }
}

public class LimitlessTradeInfo
{
    [JsonPropertyName("timestamp")]
    public long Timestamp { get; set; }

    [JsonPropertyName("price")]
    public string? Price { get; set; } // Might be string in this context

    [JsonPropertyName("size")]
    public string? Size { get; set; }

    [JsonPropertyName("side")]
    public object? Side { get; set; }

    [JsonPropertyName("transactionHash")]
    public string? TransactionHash { get; set; }
}

public class LimitlessEventResponse
{
    [JsonPropertyName("txHash")]
    public string? TxHash { get; set; }

    [JsonPropertyName("side")]
    public object? Side { get; set; }

    [JsonPropertyName("price")]
    public double? Price { get; set; }

    [JsonPropertyName("size")]
    public double? Size { get; set; }

    [JsonPropertyName("createdAt")]
    public string? CreatedAt { get; set; }

    [JsonPropertyName("profile")]
    public LimitlessProfile? Profile { get; set; }
    
    [JsonPropertyName("asset")]
    public string? Asset { get; set; }
}

public class LimitlessProfile
{
    [JsonPropertyName("account")]
    public string? Account { get; set; }
}
