using Predictalytics.Domain.Entities;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Predictalytics.Application.Interfaces;

public interface ICopytradingEstimator
{
    /// <summary>
    /// Calculates the dual-axis copytrading score (Quality & Copyability).
    /// </summary>
    Task<(decimal QualityScore, decimal CopyabilityScore, decimal CombinedScore)> CalculateScoresAsync(
        Trader trader, 
        IReadOnlyList<Trade> trades, 
        CancellationToken ct = default);

    /// <summary>
    /// Replays the trades using the historical trade tape to estimate the true alpha decay and Follower Fill Price.
    /// Returns the VWAP of the follower fill, capped by the actual volume in the latency window.
    /// </summary>
    Task<decimal?> EstimateFollowerFillPriceAsync(
        Trade traderTrade, 
        int latencySeconds = 10, 
        CancellationToken ct = default);

    /// <summary>
    /// Clusters trades into logical events (positions) based on a time window (e.g., 24h) and market.
    /// </summary>
    IReadOnlyList<TradeEvent> ClusterTradesIntoEvents(IReadOnlyList<Trade> trades, TimeSpan window);

    /// <summary>
    /// Calculates Maximum Adverse Excursion (MAE) during the holding period, handling tape sparsity.
    /// </summary>
    Task<decimal?> CalculateMaeAsync(TradeEvent tradeEvent, CancellationToken ct = default);
}

public class TradeEvent
{
    public string MarketId { get; set; } = "";
    public string AssetId { get; set; } = "";
    public Predictalytics.Domain.Enums.TradeSide Side { get; set; }
    public decimal AveragePrice { get; set; }
    public decimal TotalSize { get; set; }
    public DateTimeOffset EventStartTime { get; set; }
    public DateTimeOffset EventEndTime { get; set; }
    public List<Trade> ConstituentTrades { get; set; } = new();
}
