using Common.Dtos.Verification;
using Common.Enums;
using System.Net.Http.Json;

namespace HushianWebApp.Service
{
    public class VerificationService
    {
        private readonly BaseController _baseController;

        public VerificationService(BaseController baseController)
        {
            _baseController = baseController;
        }

        public async Task<int> FromUserName(string mobile, VerificationCodeType type)
        {

                string route = type switch
                {
                    VerificationCodeType.ForgetPassword => "ForgetPassword",
                    _ => throw new NotImplementedException()
                };
                var response = await _baseController.Get($"v1/Verification/{route}/{mobile}");
                if (response.IsSuccessStatusCode)
                {
                    return await response.Content.ReadFromJsonAsync<int>();
                }
                else
                {
                    return 0;
                }
           
            
        }
        public async Task<bool> ConfirmedCode(ConfirmedCodeDto dto)
        {
            var response = await _baseController.Post($"v1/Verification/ConfirmedCode", dto);
            return response.IsSuccessStatusCode;

        }
        public async Task<bool> ReSendCode(int ID)
        {
            var response = await _baseController.Get($"v1/Verification/ReSendCode/{ID}");
            return response.IsSuccessStatusCode;

        }
    }
}
