using DomainResults.Common;

using DataProviders.Collections;

using HashService;
using JWTService;
using WeatherForecast.Models.Requests;
using Core.Abstractions;

namespace WeatherForecast.Services {
  /// <summary>
  /// 
  /// </summary>
  public interface IPasswordService {
    /// <summary>
    /// 
    /// </summary>
    /// <param name="siteId"></param>
    /// <param name="userId"></param>
    /// <param name="password"></param>
    /// <returns></returns>
    (Guid?, IDomainResult) Post(Guid siteId, Guid userId, PasswordRequestModel requestData);
  }
 
  /// <summary>
  /// 
  /// </summary>
  public class PasswordService : ServiceBase<PasswordService>, IPasswordService {

    private readonly IHashService _hashService;
    private readonly IUserDataProvider _userDataProvider;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="logger"></param>
    /// <param name="hashService"></param>
    /// <param name="jwtService"></param>
    /// <param name="userDataProvider"></param>
    public PasswordService(
      ILogger<PasswordService> logger,
      IHashService hashService,
      
      IUserDataProvider userDataProvider
    ) : base(logger) {
      _hashService = hashService;
      
      _userDataProvider = userDataProvider;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="userName"></param>
    /// <param name="password"></param>
    /// <returns></returns>
    public (Guid?, IDomainResult) Post(Guid siteId, Guid userId, PasswordRequestModel requestData) {
      try {
        

        var (salt, hash) = _hashService.CreateSaltedHash(requestData.Password);



        return IDomainResult.Success(Guid.NewGuid());
      }
      catch (Exception ex) {
        _logger.LogError("Unhandled exception", ex);
        return IDomainResult.Failed<Guid?>();
      }
    }
  }
}
