using Knoks.Core.Data.Interfaces; using Knoks.Core.Entities; using Knoks.Core.Logic.Interfaces; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Knoks.Core.Logic.Managers { public class GeneralManager : IGeneralManager { #region Fields private readonly ILogger _logger; private readonly IGeneralDao _generalDao; private readonly IExchangeDao _exchangeDao; private readonly IUidManager _uidManager; #endregion /// /// ctor /// /// /// /// /// public GeneralManager(ILogger logger, IGeneralDao generalDao, IExchangeDao exchangeDao, IUidManager uidManager) { _logger = logger; _generalDao = generalDao; _exchangeDao = exchangeDao; _uidManager = uidManager; } public async Task> GetCountries(string countrySymbol) { if (!string.IsNullOrWhiteSpace(countrySymbol)) { if (countrySymbol.Length != 2) throw new ArgumentException("Invalid value length. The country symbol length must be 2 characters only.", countrySymbol); if (!Regex.IsMatch(countrySymbol, @"^[a-zA-Z]+$")) throw new ArgumentException("Invalid characters. The valid country symbols character must be alphabetic only.", countrySymbol); } return await _generalDao.GetCountries(countrySymbol); } public async Task> GetLanguages() { return await _generalDao.GetLanguages(); } public Task> GetCurrencies(string currency) { return _exchangeDao.GetCurrencies(currency); } public Task> GetFilterCurrencies(long? userId, bool? availableKnoks, bool? activeKnoks, bool? endedKnoks) { return _exchangeDao.GetFilterCurrencies(userId, availableKnoks, activeKnoks, endedKnoks); } public Task> GetExchanges(long? userId,bool? availableKnoks, bool? activeKnoks, bool? endedKnoks) { return _exchangeDao.GetExchanges(userId, availableKnoks, activeKnoks, endedKnoks); } public Task> GetKnokStatuses() { return _generalDao.GetKnokStatuses(); } public Task GetKnokStartValues(long exchangeId, string currency1, string currency2) { return _generalDao.GetKnokStartValues(exchangeId, currency1, currency2); } public Task> GetUserRankCount(long? userId) { return _generalDao.GetUserRank(userId); } public Task> GetKnoksLossCount(long? userId) { return _generalDao.GetKnoksLossCount(userId); } public string GetAvatarUrl(long userId) { string user = _uidManager.ToUid(userId, typeof(User), Constants.avatarCause); return $"/general/{user}/avatar"; } public Task AddKnokFeedBack(Feedback feedback) { return _generalDao.AddKnokFeedBack(feedback); } } }