using Managing.Domain.Accounts;
using Managing.Domain.Candles;
using Managing.Domain.Evm;
using Managing.Domain.Statistics;
using Managing.Domain.Trades;
using Managing.Infrastructure.Evm.Models.Privy;
using static Managing.Common.Enums;

namespace Managing.Application.Abstractions.Repositories;

public interface IEvmManager
{
    (string Key, string Secret) GenerateAddress();
    string GetAddressFromMnemo(string mnemo);
    Task<decimal> GetAddressBalance(string address);
    Task<DateTime> GetBlockDate(int blockNumber);
    Task<List<Holder>> GetContractHolders(string contractAddress, DateTime since);
    string SignMessage(string message, string privateKey);
    string VerifySignature(string signature, string message);
    Task<List<EvmBalance>> GetBalances(Chain chain, int page, int pageSize, string publicAddress);
    Task<List<EvmBalance>> GetAllBalances(Chain chain, string publicAddress);
    Task<List<EvmBalance>> GetAllBalancesOnAllChain(string publicAddress);

    Task<List<Candle>> GetCandles(Ticker ticker, DateTime startDate,
        Timeframe interval, bool isFirstCall = false);

    decimal GetVolume(SubgraphProvider subgraphProvider, Ticker ticker);
    Task<List<Ticker>> GetAvailableTicker();
    Task<Candle> GetCandle(Ticker ticker);
    Task<PrivyInitAddressResponse> InitAddress(string publicAddress);

    Task<bool> Send(Chain chain, Ticker ticker, decimal amount, string publicAddress, string privateKey,
        string receiverAddress);

    Task<EvmBalance> GetTokenBalance(string chainName, Ticker ticker, string publicAddress);
    Task<bool> CancelOrders(Account account, Ticker ticker);

    Task<Trade> IncreasePosition(Account account, Ticker ticker, TradeDirection direction, decimal price,
        decimal quantity, decimal? leverage = 1,
        decimal? stopLossPrice = null,
        decimal? takeProfitPrice = null);

    Task<Trade> GetTrade(Account account, string chainName, Ticker ticker);

    Task<Trade> DecreasePosition(Account account, Ticker ticker, TradeDirection direction, decimal price,
        decimal quantity, decimal? leverage);

    Task<decimal> QuantityInPosition(string chainName, Account account, Ticker ticker);

    Task<Trade> DecreaseOrder(Account account, TradeType tradeType, Ticker ticker, TradeDirection direction,
        decimal price, decimal quantity, decimal? leverage,
        decimal? stopLossPrice = null,
        decimal? takeProfitPrice = null);

    Task<decimal> GetFee(string chainName);
    Task<List<Trade>> GetOrders(Account account, Ticker ticker);
    Task<Trade> GetTrade(string reference, string arbitrum, Ticker ticker);
    Task<List<FundingRate>> GetFundingRates();
    Task<(string Id, string Address)> CreatePrivyWallet();

    /// <summary>
    /// Signs a message using the embedded wallet
    /// </summary>
    /// <param name="embeddedWalletId">The wallet id of the embedded wallet</param>
    /// <param name="address">The address of the embedded wallet</param>
    /// <param name="message">The message to sign</param>
    /// <returns>The signature response</returns>
    Task<string> SignMessageAsync(string embeddedWalletId, string address, string message);

    Task<List<Position>> GetPositions(Account account);
    
    /// <summary>
    /// Clears the cached balances for a specific chain and address
    /// </summary>
    /// <param name="chain">The blockchain chain</param>
    /// <param name="publicAddress">The public address</param>
    void ClearBalancesCache(Chain chain, string publicAddress);
}