using Managing.Domain.Backtests;
using Managing.Domain.Bots;
using Managing.Domain.Candles;
using Managing.Domain.Users;

namespace Managing.Application.Abstractions.Services
{
    public interface IBacktester
    {
        /// <summary>
        /// Runs a trading bot backtest with the specified configuration and date range.
        /// Automatically handles different bot types based on config.BotType.
        /// Returns a LightBacktest for efficient Orleans serialization.
        /// </summary>
        /// <param name="config">The trading bot configuration (must include Scenario object or ScenarioName)</param>
        /// <param name="startDate">The start date for the backtest</param>
        /// <param name="endDate">The end date for the backtest</param>
        /// <param name="user">The user running the backtest (optional)</param>
        /// <param name="save">Whether to save the backtest results</param>
        /// <param name="withCandles">Whether to include candles and indicators values in the response</param>
        /// <param name="requestId">The request ID to associate with this backtest (optional)</param>
        /// <param name="metadata">Additional metadata to associate with this backtest (optional)</param>
        /// <returns>The lightweight backtest results</returns>
        Task<LightBacktest> RunTradingBotBacktest(
            TradingBotConfig config,
            DateTime startDate,
            DateTime endDate,
            User user = null,
            bool save = false,
            bool withCandles = false,
            string requestId = null,
            object metadata = null);

        /// <summary>
        /// Runs a trading bot backtest with pre-loaded candles.
        /// Automatically handles different bot types based on config.BotType.
        /// Returns a LightBacktest for efficient Orleans serialization.
        /// </summary>
        /// <param name="config">The trading bot configuration (must include Scenario object or ScenarioName)</param>
        /// <param name="candles">The candles to use for backtesting</param>
        /// <param name="user">The user running the backtest (optional)</param>
        /// <param name="withCandles">Whether to include candles and indicators values in the response</param>
        /// <param name="requestId">The request ID to associate with this backtest (optional)</param>
        /// <param name="metadata">Additional metadata to associate with this backtest (optional)</param>
        /// <returns>The lightweight backtest results</returns>
        Task<LightBacktest> RunTradingBotBacktest(
            TradingBotConfig config,
            HashSet<Candle> candles,
            User user = null,
            bool withCandles = false,
            string requestId = null,
            object metadata = null);

        // Additional methods for backtest management
        Task<bool> DeleteBacktestAsync(string id);
        bool DeleteBacktests();
        IEnumerable<Backtest> GetBacktestsByUser(User user);
        Task<IEnumerable<Backtest>> GetBacktestsByUserAsync(User user);
        IEnumerable<Backtest> GetBacktestsByRequestId(string requestId);
        Task<IEnumerable<Backtest>> GetBacktestsByRequestIdAsync(string requestId);
        (IEnumerable<LightBacktest> Backtests, int TotalCount) GetBacktestsByRequestIdPaginated(string requestId, int page, int pageSize, string sortBy = "score", string sortOrder = "desc");
        Task<(IEnumerable<LightBacktest> Backtests, int TotalCount)> GetBacktestsByRequestIdPaginatedAsync(string requestId, int page, int pageSize, string sortBy = "score", string sortOrder = "desc");
        Task<Backtest> GetBacktestByIdForUserAsync(User user, string id);
        Task<bool> DeleteBacktestByUserAsync(User user, string id);
        Task<bool> DeleteBacktestsByIdsForUserAsync(User user, IEnumerable<string> ids);
        bool DeleteBacktestsByUser(User user);
        Task<bool> DeleteBacktestsByRequestIdAsync(string requestId);
        (IEnumerable<LightBacktest> Backtests, int TotalCount) GetBacktestsByUserPaginated(User user, int page, int pageSize, string sortBy = "score", string sortOrder = "desc");
        Task<(IEnumerable<LightBacktest> Backtests, int TotalCount)> GetBacktestsByUserPaginatedAsync(User user, int page, int pageSize, string sortBy = "score", string sortOrder = "desc");

        // Bundle backtest methods
        void InsertBundleBacktestRequestForUser(User user, BundleBacktestRequest bundleRequest);
        IEnumerable<BundleBacktestRequest> GetBundleBacktestRequestsByUser(User user);
        Task<IEnumerable<BundleBacktestRequest>> GetBundleBacktestRequestsByUserAsync(User user);
        BundleBacktestRequest? GetBundleBacktestRequestByIdForUser(User user, string id);
        Task<BundleBacktestRequest?> GetBundleBacktestRequestByIdForUserAsync(User user, string id);
        void UpdateBundleBacktestRequest(BundleBacktestRequest bundleRequest);
        Task UpdateBundleBacktestRequestAsync(BundleBacktestRequest bundleRequest);
        void DeleteBundleBacktestRequestByIdForUser(User user, string id);
        Task DeleteBundleBacktestRequestByIdForUserAsync(User user, string id);
        IEnumerable<BundleBacktestRequest> GetBundleBacktestRequestsByStatus(BundleBacktestRequestStatus status);
        Task<IEnumerable<BundleBacktestRequest>> GetBundleBacktestRequestsByStatusAsync(BundleBacktestRequestStatus status);


    }
}