using Knoks.Core.Data.Interfaces;
using Knoks.Core.Entities;
using Knoks.Core.Logic.Interfaces;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System;
using System.Collections.ObjectModel;
using Knoks.Api.Logic.Interfaces;
using Knoks.Api.Data.Interfaces;
using Knoks.Api.Entities;

namespace Knoks.Api.Logic.Managers
{
    public class ApiConsumerManager : IApiConsumerManager, IInitializable
    {
        private readonly ILogger<ApiConsumerManager> _logger;
        private readonly IApiConsumerDao _apiConsumerDao;

        public ApiConsumerManager(ILogger<ApiConsumerManager> logger, IApiConsumerDao apiConsumerDao)
        {
            _logger = logger;
            _apiConsumerDao = apiConsumerDao;
        }

        public IDictionary<string, ApiConsumer> ApiConsumers { get; private set; }

        public async Task Initialize()
        {
            ApiConsumers = new ReadOnlyDictionary<string, ApiConsumer>((await _apiConsumerDao.GetApiConsumers()).ToDictionary(el => el.ApiIdentifier.ToString("N"), StringComparer.OrdinalIgnoreCase));
        }
    }
}
