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

namespace Knoks.CryptoExchanges.Data.Dao
{
    public class KnokDao : IKnokDao
    {
        private IProcExecutor executor;
        public KnokDao(IProcExecutor executor)
        {
            this.executor = executor;
        }
        public async Task<IEnumerable<Tuple<string, string>>> GetActiveKnoksDataByExchange(int exchangeId)
        {
            return (await executor.Go(DatabaseNames.Prices, "GetActivePair", new { ExchangeId = exchangeId }))
                .Тables[0].ToList<KnoksPairsData>()
                .Select(it => new Tuple<string, string>(it.Base, it.NonBase));
        }

        public async Task RecalcAggregations()
        {
            await executor.Go(DatabaseNames.Prices, "RecalcAggregations");
        }

        private class KnoksPairsData
        {
            public int ExchangeId { get; set; }
            public string Base { get; set; }
            public string NonBase { get; set; }
            public DateTime? LastDate { get; set; }
        }
    }
}
