using ReserveManagementSystemLib.Configuration; using LCU.Library.Internal.ApiSecurity.Models; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.IndirectLoan; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Transaction; using LCU.Library.Internal.LcuHttpClient.HttpRequest; using LCU.Library.Internal.ApiSecurity.Enums; using LCU.Library.Internal.LcuHttpClient.Utilities; namespace ReserveManagementSystemApi.ServiceClients { public class CoreApiServiceClient : ICoreApiServiceClient { private readonly ApiSecurityConfiguration _apiSecurityConfiguration; private readonly CoreApiConfiguration _coreApiWrapperConfiguration; private readonly IPostRequest _postRequest; private readonly IGetRequest _getRequest; private readonly IPutRequest _putRequest; private const string ClientKeyValue = "ReserveManagementSystem"; public CoreApiServiceClient( ApiSecurityConfiguration apiSecurityConfiguration, CoreApiConfiguration coreApiWrapperConfiguration, IGetRequest getRequest, IPostRequest postRequest, IPutRequest putRequest ) { _apiSecurityConfiguration = apiSecurityConfiguration; _coreApiWrapperConfiguration = coreApiWrapperConfiguration; _getRequest = getRequest; _postRequest = postRequest; _putRequest = putRequest; } public async Task> PostMonetaryTransactions(List loanReserves) { try { var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.PostMonetaryTransactions}"; var uri = new Uri(path); var response = await _postRequest.Async, List>(uri, loanReserves, HttpUtilities.GetApiKeyHeaders(ClientKeyValue, _apiSecurityConfiguration.ExtractApiKey(ClientKeyValue, ApiKeySetName.InternalKeySet)), 0, Convert.ToInt16(_coreApiWrapperConfiguration.ApiTimeOutInSeconds)); return response; } catch (Exception ex) { Log.Error(ex, "Error in posting MonetaryTransactions."); throw; } } public async Task> PutDealerOriginalBalance(string accountNumber) { try { var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.PutDealerOriginalBalance}"; var uri = new Uri(path); var response = await _putRequest.Async>(uri, accountNumber, HttpUtilities.GetApiKeyHeaders(ClientKeyValue, _apiSecurityConfiguration.ExtractApiKey(ClientKeyValue, ApiKeySetName.InternalKeySet)), 0, Convert.ToUInt16(_coreApiWrapperConfiguration.ApiTimeOutInSeconds)); return response; } catch (Exception ex) { Log.Error(ex, "Error updating Dealer Original Balance"); throw; } } public async Task> GetIndirectLoansByPostedDate(string afterPostDate) { try { var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.GetIndirectLoansByPostedDate}{afterPostDate}"; var response = await _getRequest.AsyncWithNewton>(path, null, 0, Convert.ToUInt16(_coreApiWrapperConfiguration.ApiTimeOutInSeconds)); return response; } catch (Exception ex) { Log.Error(ex, "Error getting Indirect Loans By Posted Date"); return null; } } public async Task> GetClosedLoansByPostedDate(string afterPostDate) { try { var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.GetClosedLoansByPostedDate}{afterPostDate}"; var response = await _getRequest.AsyncWithNewton>(path); return response; } catch (Exception ex) { Log.Error(ex, "Error getting Closed Loans By Posted Date"); } return null; } public async Task> GetClosedLoansWithDetailByClosedDate(string afterClosedDate) { try { var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.GetClosedIndirectLoansWithDetailByPostedDate}{afterClosedDate}"; var response = await _getRequest.AsyncWithNewton>(path); return response; } catch (Exception ex) { Log.Error(ex, "Error getting Closed Loans With Detail"); } return null; } } }