package com.seer.teach.pay.api.wallet;

import com.seer.teach.pay.api.wallet.dto.CoinAccountRefundDTO;
import com.seer.teach.pay.api.wallet.dto.WechatRefundRespDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@Validated
@Slf4j
@RequiredArgsConstructor
public class CoinAccountRefundServiceApiImpl implements CoinAccountRefundServiceApi{


    @Override
    public WechatRefundRespDTO submitRefundApply(CoinAccountRefundDTO coinAccountRefundDTO) {
        // 充值订单号
        String outTradeNo = coinAccountRefundDTO.getOutTradeNo();
        // 退款原因
        String refundReason = coinAccountRefundDTO.getRefundReason();
        // 退款金额(单位转换为分)
        long refundAmount = coinAccountRefundDTO.getRefundAmount().multiply(new BigDecimal(100)).longValue();
        // 原订单总金额(单位转换为分)
        long totalAmount = coinAccountRefundDTO.getTotalAmount().multiply(new BigDecimal(100)).longValue();
        // 退款订单号
        String refundSn = coinAccountRefundDTO.getRefundSn();
        
        log.info("提交微信退款参数: 充值订单号={}, 退款原因={}, 退款金额={}分, 原订单总金额={}分, 退款订单号={}", 
                 outTradeNo, refundReason, refundAmount, totalAmount, refundSn);
        
       // RefundSubmitRespDTO wechatRefundResp = wechatPlayClient.submitRefund(outTradeNo, refundReason, refundAmount, totalAmount, refundSn);
        //log.info("提交微信退款结果: {}", wechatRefundResp);
        
        //return CoinAccountRefundConvert.INSTANCE.convertOne(wechatRefundResp);
        return null;
    }

    @Override
    public WechatRefundRespDTO queryRefund(String refundSn) {
        log.info("CoinAccountRefundServiceApi 查询微信退款参数: 退款单号={}", refundSn);
//        RefundSubmitRespDTO wechatRefundResp = wechatPlayClient.queryRefund(refundSn);
//        log.info("CoinAccountRefundServiceApi 查询微信退款结果: {}", wechatRefundResp);
//        return CoinAccountRefundConvert.INSTANCE.convertOne(wechatRefundResp);
        return null;
    }
}