using Common.Constant;
using Microsoft.AspNetCore.Mvc;
using SicboSub.Api.Business;
using SicboSub.Api.DTO;

namespace SicboSub.Api.Controllers
{
    /// <summary>
    /// Controller cho Exchange APIs (Rút thưởng với xác thực OTP)
    /// </summary>
    [ApiController]
    public class ExchangeController : Controller
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ExchangeController));

        private readonly IExchangeBusiness exchangeBusiness;

        public ExchangeController(IExchangeBusiness exchangeBusiness)
        {
            this.exchangeBusiness = exchangeBusiness;
        }

        /// <summary>
        /// Yêu cầu OTP để thực hiện rút thưởng
        /// POST /apis/exchange/request-otp
        /// </summary>
        [HttpPost]
        [Route(ApiUrlConstant.ExchangeRequestOtpUrl)]
        public async Task<IActionResult> RequestOtp([FromBody] ExchangeRequestOtpReq request)
        {
            return await exchangeBusiness.RequestOtp(HttpContext.Request, request);
        }

        /// <summary>
        /// Xác thực OTP và thực hiện rút thưởng
        /// POST /apis/exchange/verify-otp
        /// </summary>
        [HttpPost]
        [Route(ApiUrlConstant.ExchangeVerifyOtpUrl)]
        public async Task<IActionResult> VerifyOtp([FromBody] ExchangeVerifyOtpReq request)
        {
            return await exchangeBusiness.VerifyOtp(HttpContext.Request, request);
        }

        /// <summary>
        /// Gửi lại OTP
        /// POST /apis/exchange/resend-otp
        /// </summary>
        [HttpPost]
        [Route(ApiUrlConstant.ExchangeResendOtpUrl)]
        public async Task<IActionResult> ResendOtp([FromBody] ExchangeResendOtpReq request)
        {
            return await exchangeBusiness.ResendOtp(HttpContext.Request, request);
        }

        /// <summary>
        /// Lấy lịch sử rút đổi thưởng
        /// POST /apis/exchange/history
        /// </summary>
        [HttpPost]
        [Route(ApiUrlConstant.ExchangeHistoryUrl)]
        public async Task<IActionResult> GetHistory([FromBody] ExchangeHistoryReq request)
        {
            return await exchangeBusiness.GetHistory(HttpContext.Request, request);
        }
    }
}
