using Managing.Domain.Accounts;
using Managing.Domain.Bots;
using Managing.Domain.Candles;
using Managing.Domain.Indicators;
using Managing.Domain.Scenarios;
using Managing.Domain.Statistics;
using Managing.Domain.Strategies;
using Managing.Domain.Strategies.Base;
using Managing.Domain.Synth.Models;
using Managing.Domain.Trades;
using Managing.Domain.Users;
using Managing.Infrastructure.Evm.Models.Privy;
using static Managing.Common.Enums;

namespace Managing.Application.Abstractions.Services;

public interface ITradingService
{
    Task<Scenario> GetScenarioByNameAsync(string scenario);
    Task InsertPositionAsync(Position position);
    Task UpdatePositionAsync(Position position);
    Task<IndicatorBase> GetIndicatorByNameAsync(string strategy);
    Task InsertScenarioAsync(Scenario scenario);
    Task InsertIndicatorAsync(IndicatorBase indicatorBase);
    Task<IEnumerable<Scenario>> GetScenariosAsync();
    Task<IEnumerable<Scenario>> GetScenariosByUserAsync(User user);
    Task<IEnumerable<IndicatorBase>> GetIndicatorsAsync();
    Task DeleteScenarioAsync(string name);
    Task DeleteIndicatorAsync(string name);
    Task<Position> GetPositionByIdentifierAsync(Guid identifier);
    Task<Position> ManagePosition(Account account, Position position);

    Task WatchTrader();
    Task<IEnumerable<Trader>> GetTradersWatch();
    Task UpdateScenarioAsync(Scenario scenario);
    Task UpdateIndicatorAsync(IndicatorBase indicatorBase);
    Task<IEnumerable<Position>> GetBrokerPositions(Account account);
    Task<IEnumerable<Position>> GetAllDatabasePositionsAsync();
    Task<IEnumerable<Position>> GetPositionsByInitiatorIdentifierAsync(Guid initiatorIdentifier);
    Task<IEnumerable<Position>> GetPositionsByInitiatorIdentifiersAsync(IEnumerable<Guid> initiatorIdentifiers);
    Task<PrivyInitAddressResponse> InitPrivyWallet(string publicAddress);

    // Synth API integration methods
    Task<SignalValidationResult> ValidateSynthSignalAsync(LightSignal signal, decimal currentPrice,
        TradingBotConfig botConfig,
        bool isBacktest);

    Task<bool> AssessSynthPositionRiskAsync(Ticker ticker, TradeDirection direction, decimal currentPrice,
        TradingBotConfig botConfig, bool isBacktest);

    Task<SynthRiskResult> MonitorSynthPositionRiskAsync(Ticker ticker, TradeDirection direction, decimal currentPrice,
        decimal liquidationPrice, Guid positionIdentifier, TradingBotConfig botConfig);

    /// <summary>
    /// Calculates indicators values for a given scenario and candles.
    /// </summary>
    /// <param name="scenario">The scenario containing indicators.</param>
    /// <param name="candles">The candles to calculate indicators for.</param>
    /// <returns>A dictionary of indicator types to their calculated values.</returns>
    Dictionary<IndicatorType, IndicatorsResultBase> CalculateIndicatorsValuesAsync(
        Scenario scenario,
        HashSet<Candle> candles);

    Task<IndicatorBase?> GetIndicatorByNameUserAsync(string name, User user);
    Task<Scenario?> GetScenarioByNameUserAsync(string scenarioName, User user);
}