using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Text;
using Znyc.CloudCar.IServices.Auth;
using Znyc.CloudCar.Model.ViewModels.ReportsCallBack;

namespace Znyc.CloudCar.Controller
{
    public class WxPayController : ControllerBase
    {
        private readonly IAuthService _authService;

        public WxPayController(IAuthService authService)
        {
            _authService = authService;
        }


        /// <summary>
        ///     微信小程序支付
        /// </summary>
        /// <param name="productId">商品Id</param>
        /// <param name="type">1充值,2优惠卡</param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        [Route("api/v1/wxpay/{productId}/{type}")]
        public Task<ResponseOutput> WxPay(long productId, int type)
        {
            return _authService.WxPay(productId, type);
        }

        /// <summary>
        ///     微信小程序支付回调
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("api/v1/wxpay/notify")]
        public async Task<string> NotifyUrl()
        {
            using var reader = new StreamReader(Request.Body, Encoding.UTF8);
            string content = await reader.ReadToEndAsync();
            return await _authService.NotifyUrl(content);
        }
    }
}