using System;
using Common;
using Common.Constant;
using Common.Http;
using Esim.Apis.Business;
using Database.Database;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace RevoSystem.Apis.Controllers
{
    [ApiController]
    public class UserController : Controller
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
            typeof(UserController)
        );

        ModelContext dbContext;
        IConfiguration configuration;

        IUserBusiness userBusiness;

        public UserController(
            IConfiguration _configuration,
            IUserBusiness userBusiness,
            ModelContext dbContext
        )
        {
            configuration = _configuration;
            this.userBusiness = userBusiness;
            this.dbContext = dbContext;
        }

        private string GetParameter(string key)
        {
            return configuration.GetSection(key).Value ?? "";
        }

        /// <summary>
        /// Request OTP via email
        /// POST /apis/auth/request-otp
        /// </summary>
        [HttpPost]
        [Route(ApiUrlConstant.RequestOtpUrl)]
        public async Task<IActionResult> RequestOtp(RequestOtpReq request)
        {
            return await userBusiness.RequestOtp(HttpContext.Request, request);
        }

        /// <summary>
        /// Verify OTP and complete login
        /// POST /apis/auth/verify-otp
        /// </summary>
        [HttpPost]
        [Route(ApiUrlConstant.VerifyOtpUrl)]
        public async Task<IActionResult> VerifyOtp(VerifyOtpReq request)
        {
            return await userBusiness.VerifyOtp(HttpContext.Request, request);
        }

    }
}
