using Kraken.Net.Objects.Models;
using Managing.Core;
using Managing.Domain.Trades;
using static Managing.Common.Enums;

namespace Managing.Infrastructure.Exchanges.Helpers;

public static class KrakenHelpers
{
    public static Trade Map(KrakenOrder order)
    {
        var leverageParse = order.OrderDetails.Leverage.Split((char)':')[0];
        long.TryParse(leverageParse, out long leverage);

        return new Trade(order.CreateTime,
            TradeDirection.None,
            (TradeStatus)order.Status,
            (TradeType)order.OrderDetails.Type,
            MiscExtensions.ParseEnum<Ticker>(order.OrderDetails.Symbol),
            order.Quantity,
            order.AveragePrice,
            leverage,
            order.ClientOrderId,
            "");
    }

    public static Kraken.Net.Enums.OrderType KrakenOrderTypeMap(TradeType tradeType)
    {
        switch (tradeType)
        {
            case TradeType.Limit:
                return Kraken.Net.Enums.OrderType.Limit;
            case TradeType.Market:
                return Kraken.Net.Enums.OrderType.Market;
            case TradeType.StopMarket:
                return Kraken.Net.Enums.OrderType.StopMarket;
            default:
                return Kraken.Net.Enums.OrderType.Limit;
        }
    }

    internal static Trade Map(KeyValuePair<string, KrakenOrder> o)
    {
        throw new NotImplementedException();
    }
}
