using Predictalytics.Domain.Entities;
using Predictalytics.Domain.Enums;

namespace Predictalytics.Domain.Interfaces;

public interface ITraderRepository
{
    Task<Trader?> GetByIdAsync(int id, CancellationToken ct = default);
    Task<Trader?> GetByPlatformIdAsync(PlatformType platform, string platformUserId, CancellationToken ct = default);
    Task<IReadOnlyList<Trader>> GetAllAsync(PlatformType? platform = null, int skip = 0, int take = 50, CancellationToken ct = default);
    Task<IReadOnlyList<Trader>> GetWatchlistedAsync(CancellationToken ct = default);
    Task<IReadOnlyList<Trader>> GetTopByScoreAsync(int count = 20, CancellationToken ct = default);
    Task<IReadOnlyList<Trader>> GetTopByPnLAsync(int count = 5, DateTime? since = null, CancellationToken ct = default);
    Task<int> GetCountAsync(PlatformType? platform = null, CancellationToken ct = default);
    Task AddAsync(Trader trader, CancellationToken ct = default);
    Task UpdateAsync(Trader trader, CancellationToken ct = default);
    Task DeleteAsync(int id, CancellationToken ct = default);
    Task UpdateRanksAsync(IEnumerable<(int TraderId, int Rank)> ranks, CancellationToken ct = default);

    /// <summary>Get traders that need trade history update (LastTradesUpdatedAt is null or older than given hours).</summary>
    Task<IReadOnlyList<Trader>> GetTradersDueForTradeUpdateAsync(int cooldownHours = 6, int take = 20, CancellationToken ct = default);

    /// <summary>Get traders that haven't been polled in a long time or have a prolonged API error for cleanup.</summary>
    Task<IReadOnlyList<Trader>> GetTradersForCleanupAsync(DateTime inactiveSince, DateTime errorSince, int take = 50, CancellationToken ct = default);

    /// <summary>Get traders ordered by LastPolledAt to ensure round-robin polling of all traders.</summary>
    Task<IReadOnlyList<Trader>> GetTradersForPollingAsync(int take, CancellationToken ct = default);

    Task<IReadOnlyList<Trader>> SearchAsync(string query, int take = 20, CancellationToken ct = default);

    Task<IReadOnlyList<TraderPosition>> GetPositionsAsync(int traderId, CancellationToken ct = default);
}
