using Knoks.CryptoExchanges.Data.Interfaces;
using Knoks.CryptoExchanges.Entities;
using Knoks.CryptoExchanges.Entities.Args;
using Knoks.Framework.DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Knoks.Framework.Extentions;

namespace Knoks.CryptoExchanges.Data.Dao
{
    public class ExchangePairRateDao : IExchangePairRateDao
    {
        private IProcExecutor executor;
        public ExchangePairRateDao(IProcExecutor executor)
        {
            this.executor = executor;
        }
        public async Task UpdateExchangePairRate(int exchangeId, ExchangePairRateArg arg)
        {
            await executor.Go(DatabaseNames.Prices, "Agg_1Minute", arg, new { ExchangeId = exchangeId });
        }

        public async Task<List<LiveRateItem>> GetLiveRates(List<LiveRateItemRequest> searchItems)
        {
            var dbTable = await executor.Go(DatabaseNames.Prices, "KST_GetUpdatedLiveRates", new { SearchItemsList = searchItems.ToDataTable()});
            return dbTable.Тables[0].Rows.Select(row => row.To<LiveRateItem>()).ToList();
        }
    }
}
