import {ApiCall} from "tsrpc";
import {ReqPay, ResPay} from "../../monopoly/protocols/gm/PtlPay";
import {PayFun} from "../../public/pay";
import { clusterFunctionRunAtUidProcess } from "../../clusterUtils";

export default async function (call: ApiCall<ReqPay, ResPay>) {

    clusterFunctionRunAtUidProcess(call.req.uid , "pay", call.req.uid, call.req.payId, call.req.payArgs, call.req.type, call.req.orderNo)
    //await PayFun.pay(call.req.uid, call.req.payId, call.req.payArgs, call.req.type, call.req.orderNo);
    call.succ({});

    // 5秒后自动检测支付
    setTimeout(async function(){
        let payed = await G.mongodb.collection('payOrderLog' as any).count({"orderNo": call.req.orderNo});
        if(!payed){
            await PayFun.pay(call.req.uid, call.req.payId, call.req.payArgs, call.req.type, call.req.orderNo);
        }
    },5000)
}