using Binance.Net.Interfaces;
using FTX.Net.Objects.Models;
using Kraken.Net.Objects.Models;
using Managing.Domain.Candles;
using Managing.Infrastructure.Databases.MongoDb.Collections;
using static Managing.Common.Enums;

namespace Managing.Infrastructure.Exchanges
{
    public static class CandleHelpers
    {
        public static CandleDto Convert(IBinanceKline candle, Ticker ticker, Timeframe timeframe)
        {
            return new CandleDto()
            {
                Ticker = ticker.ToString(),
                Timeframe = timeframe,
                BaseVolume = candle.Volume,
                Close = candle.ClosePrice,
                CloseTime = candle.CloseTime,
                Open = candle.OpenPrice,
                OpenTime = candle.OpenTime,
                High = candle.HighPrice,
                Low = candle.LowPrice,
                QuoteVolume = candle.QuoteVolume,
                TakerBuyBaseVolume = candle.TakerBuyBaseVolume,
                TakerBuyQuoteVolume = candle.TakerBuyQuoteVolume,
                TradeCount = candle.TradeCount,
            };
        }

        public static CandleDto Convert(KrakenStreamKline candle, Ticker ticker, Timeframe timeframe)
        {
            return new CandleDto()
            {
                Ticker = ticker.ToString(),
                Timeframe = timeframe,
                BaseVolume = candle.Volume,
                Close = candle.ClosePrice,
                CloseTime = candle.CloseTime,
                Open = candle.OpenPrice,
                OpenTime = candle.OpenTime,
                High = candle.HighPrice,
                Low = candle.LowPrice,
                QuoteVolume = candle.VolumeWeightedAveragePrice,
                TradeCount = candle.TradeCount
            };
        }

        internal static Candle Map(FTXKline lastCandle)
        {
            return new Candle
            {
                OpenTime = lastCandle.OpenTime,
                High = lastCandle.HighPrice,
                Low = lastCandle.LowPrice,
                Close = lastCandle.ClosePrice,
                Open = lastCandle.OpenPrice
            };
        }

        internal static Candle Map(IBinanceStreamKline candle, Ticker ticker, Timeframe timeframe)
        {
            return new Candle()
            {
                Ticker = ticker.ToString(),
                Timeframe = timeframe,
                BaseVolume = candle.Volume,
                Close = candle.ClosePrice,
                Date = candle.CloseTime,
                Open = candle.OpenPrice,
                OpenTime = candle.OpenTime,
                High = candle.HighPrice,
                Low = candle.LowPrice,
                QuoteVolume = candle.QuoteVolume,
                TakerBuyBaseVolume = candle.TakerBuyBaseVolume,
                TakerBuyQuoteVolume = candle.TakerBuyQuoteVolume,
                TradeCount = candle.TradeCount,
            };
        }
    }
}
