using AutoMapper;
using DigitalData.Core.Client.Interface;
using DigitalData.Core.Client;
using EnvelopeGenerator.Application.Configurations;
using EnvelopeGenerator.Application.Interfaces.Services;
using EnvelopeGenerator.Application.Dto.Messaging;
using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.Application.Services;
//TODO: move to DigitalData.Core
///
///
///
public class GTXSmsSender : ISmsSender
{
private readonly IHttpClientService _smsClient;
private readonly GtxMessagingParams _smsParams;
private readonly IMapper _mapper;
///
///
///
public string ServiceProvider { get; }
///
///
///
///
///
///
public GTXSmsSender(IHttpClientService smsClient, IOptions smsParamsOptions, IMapper mapper)
{
_smsClient = smsClient;
_smsParams = smsParamsOptions.Value;
_mapper = mapper;
ServiceProvider = GetType().Name.Replace("Service", string.Empty);
}
///
///
///
///
///
///
public async Task SendSmsAsync(string recipient, string message)
{
return await _smsClient.FetchAsync(queryParams: new Dictionary()
{
{ _smsParams.RecipientQueryParamName, recipient },
{ _smsParams.MessageQueryParamName, message }
})
.ThenAsync(res => res.Json())
.ThenAsync(_mapper.Map);
}
}