package org.tio.sitexxx.service.service.pay.impl.ncount;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.http.common.HttpRequest;
import org.tio.jfinal.kit.Ret;
import org.tio.sitexxx.service.service.pay.base.BaseCallbackPay;
import org.tio.sitexxx.service.service.pay.base.BasePayResp;
import org.tio.sitexxx.service.service.pay.base.BaseRespFormatPay;
import org.tio.sitexxx.service.service.pay.utils.ncount.NRequestUtils;
import org.tio.utils.json.Json;

/**
 * <pre>
 *    @author : vagrancy
 *    e-mail : 18050829067@163.com
 *    time   : 2025-11-26 11:32
 *    desc   :
 * </pre>
 */
public class PayNCountCallbackApi implements BaseCallbackPay<BasePayResp> {

    private static Logger log = LoggerFactory.getLogger(PayNCountCallbackApi.class);

    private BaseRespFormatPay formatPay = new PayNCountFormatApi();

    @Override
    public BasePayResp recharge(HttpRequest request, Integer uid) {
        try {
            Ret ret = NRequestUtils.callback(request, PayNCountConst.TranCode.RECHARGE_CONFIRM);
            BasePayResp resp = NRequestUtils.checkRet(ret);
            if (resp.isOk()) {
                resp.setResp(formatPay.rechargeCallback(resp.getResp(), uid));
                log.error("解析后的map:{}", Json.toJson(resp.getResp()));
            }
            return resp;
        } catch (Exception e) {
            log.error("", e);
        }
        return BasePayResp.fail("系统异常", "-1");
    }

    @Override
    public BasePayResp withhold(HttpRequest request, Integer uid) {
        try {
            Ret ret = NRequestUtils.callback(request, PayNCountConst.TranCode.WITHHOLD);
            BasePayResp resp = NRequestUtils.checkRet(ret);
            if (resp.isOk()) {
                resp.setResp(formatPay.withholdCallback(resp.getResp(), uid));
            }
            return resp;
        } catch (Exception e) {
            log.error("", e);
        }
        return BasePayResp.fail("系统异常", "-1");
    }

    @Override
    public BasePayResp sendRedpacket(HttpRequest request, Integer uid) {
        try {
            Ret ret = NRequestUtils.callback(request, PayNCountConst.TranCode.RECHARGE_CONFIRM);
            BasePayResp resp = NRequestUtils.checkRet(ret);
            if (resp.isOk()) {
                resp.setResp(formatPay.rechargeCallback(resp.getResp(), uid));
                log.error("解析后的map:{}", Json.toJson(resp.getResp()));
            }
            return resp;
        } catch (Exception e) {
            log.error("", e);
        }
        return BasePayResp.fail("系统异常", "-1");
    }
}

