using HermesSocketServer.Models;
using HermesSocketServer.Store;
using ILogger = Serilog.ILogger;

namespace HermesSocketServer.Requests
{
    public class GetDefaultTTSVoice : IRequest
    {
        public string Name => "get_default_tts_voice";
        public string[] RequiredKeys => [];
        private readonly UserStore _users;
        private readonly ServerConfiguration _configuration;
        private readonly ILogger _logger;

        public GetDefaultTTSVoice(UserStore users, ServerConfiguration configuration, ILogger logger)
        {
            _users = users;
            _configuration = configuration;
            _logger = logger;
        }

        public async Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
        {
            var user = _users.Get(channel.Id);
            if (user == null)
                return RequestResult.Failed("Unable to find user data.", notifyClientsOnAccount: false);
            
            return RequestResult.Successful(user.DefaultVoice ?? _configuration.Tts.DefaultTtsVoice, notifyClientsOnAccount: false);
        }
    }
}