using Knoks.Api.Data.Interfaces;
using Knoks.Api.Entities;
using Knoks.Framework.DataAccess;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Knoks.Api.Data.Dao
{
    public class ApiConsumerDao : IApiConsumerDao
    {
        private readonly IProcExecutor _executor;
        private readonly ILogger<ApiConsumerDao> _logger;

        public ApiConsumerDao(IProcExecutor executor, ILogger<ApiConsumerDao> logger)
        {
            _logger = logger;
            _executor = executor;
        }

        public async Task<IEnumerable<ApiConsumer>> GetApiConsumers()
        {
            _logger.LogDebug("GetApiConsumers invoked");
            return (await _executor.Go("API_GetApiConsumers")).Тables[0].Rows.Select(row => row.To<ApiConsumer>());
        }
    }
}
