package com.fdkankan.ucenter.httpClient.service;

import com.alibaba.fastjson.JSONObject;
import com.dtflys.forest.annotation.Get;
import com.dtflys.forest.annotation.JSONBody;
import com.dtflys.forest.annotation.Post;
import com.dtflys.forest.annotation.Var;
import com.fdkankan.ucenter.common.ResultData;
import com.fdkankan.ucenter.httpClient.client.PayClient;
import com.fdkankan.ucenter.httpClient.param.PayAutoPayVo;
import com.fdkankan.ucenter.httpClient.param.PayGoods;
import com.fdkankan.ucenter.httpClient.param.PayOrderParam;
import com.fdkankan.ucenter.httpClient.vo.PayOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class PayService {

    @Autowired
    PayClient payClient;

    public PayOrderVo downOrder(BigDecimal money, String type, String userName, String nickName, List<PayGoods> goodsInfo, PayAutoPayVo autoPayVo){
        PayOrderParam   param = new PayOrderParam(money,type,userName,nickName,goodsInfo,autoPayVo);
        ResultData resultData = payClient.downOrder(param);
        if(resultData.getCode() == 200 ){
            String orderStr = JSONObject.toJSONString(resultData.getData());
            return JSONObject.parseObject(orderStr,PayOrderVo.class);
        }
        return null;
    }


    /**
     * 查询订单状态
     */
    public PayOrderVo queryOrder(String orderSn){
        ResultData resultData = payClient.queryOrder(orderSn);
        if(resultData.getCode() == 200 ){
            String orderStr = JSONObject.toJSONString(resultData.getData());
            return JSONObject.parseObject(orderStr,PayOrderVo.class);
        }
        return null;
    }
}
