using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using LCU.Library.Internal.ApiSecurity.Enums; using LCU.Library.Internal.ApiSecurity.Models; using LCU.Library.Internal.CoreApiWrapperLib.Configuration; using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities; using LCU.Library.Internal.CoreApiWrapperLib.Utilities; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreResponses; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreSoapRequests; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.MemberAgreements; using LCU.Library.Internal.LcuHttpClient.HttpRequest; namespace LCU.Library.Internal.CoreApiWrapperLib.DataAccess { public class AgreePersonDao : IAgreePersonDao { private readonly ICoreDbExecution _coreDbExecution; private readonly CoreSoapApiConfiguration _coreSoapApiConfiguration; private readonly ApiSecurityConfiguration _apiSecurityConfiguration; private readonly IPutRequest _putRequest; private const string SoapClientKeyValue = "CoreSoapApiWrapper"; private const string AgreePersonByUserIdQuery = "AgreePerson/AgreePersonByUserIdQuery"; private const string GetAgreePersonsQuery = "AgreePerson/GetAgreePersonsQuery"; private const string AgreePersonsWithHyphenatedUserIdQuery = "AgreePerson/AgreePersonsWithHyphenatedUserIdQuery"; private const string GetActiveCustodialAgreePersonNumbers = "AgreePerson/GetActiveCustodialAgreePersonNumbers"; private const string GetActiveCustodialVruCardAgreementAgreePersons = "AgreePerson/GetActiveCustodialVruCardAgreementAgreePersons"; public AgreePersonDao(ICoreDbExecution coreDbExecution, CoreConfiguration coreConfiguration, ApiSecurityConfiguration apiSecurityConfiguration, IPutRequest putRequest) { _coreDbExecution = coreDbExecution; _coreSoapApiConfiguration = coreConfiguration.CoreSoapApiConfiguration; _apiSecurityConfiguration = apiSecurityConfiguration; _putRequest = putRequest; } public async Task FindByUserId(string userId) { var query = QueryUtilities.GetQuery(AgreePersonByUserIdQuery); var userIdParams = new { userId = userId }; var result = await _coreDbExecution.ExecuteQuery(query, userIdParams); return result.FirstOrDefault(); } public async Task> FindAgreePersons(int fetchAmount) { var query = QueryUtilities.GetQuery(GetAgreePersonsQuery); var fectAmountParam = new { fetchAmount = fetchAmount }; var result = await _coreDbExecution.ExecuteQuery(query, fectAmountParam); return result; } public async Task> FindAgreePersonsWithHyphenatedUserId() { var query = QueryUtilities.GetQuery(AgreePersonsWithHyphenatedUserIdQuery); var result = await _coreDbExecution.ExecuteQuery(query); return result; } public async Task> FindActiveCustodialAgreePersonNumbers() { var query = QueryUtilities.GetQuery(GetActiveCustodialAgreePersonNumbers); var result = await _coreDbExecution.ExecuteQuery(query); return result; } public async Task> FindActiveCustodialVruCardAgreementAgreePersons() { var query = QueryUtilities.GetQuery(GetActiveCustodialVruCardAgreementAgreePersons); var result = await _coreDbExecution.ExecuteQuery(query); return result; } public async Task UpdatePersonAgreementDetailTypes(PersonAgreementDetailTypeRequest personAgreementDetailTypeRequest) { var endpoint = HttpUtilities.BuildHttpsUri(_coreSoapApiConfiguration.CoreSoapApiWrapperHost, _coreSoapApiConfiguration.CoreSoapEndpointConfiguration.PutPersonAgreementsDetailTypes); var headers = LcuHttpClient.Utilities.HttpUtilities.GetApiKeyHeaders(SoapClientKeyValue, _apiSecurityConfiguration.ExtractApiKey(SoapClientKeyValue, ApiKeySetName.InternalKeySet)); return await _putRequest.Async(endpoint, personAgreementDetailTypeRequest, headers, 0); } } }