package com.hfkj.qianzhu;

import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;

import java.util.Map;

/**
 * @ClassName KfcService
 * @Author Sum1Dream
 * @Description
 * @Date 2024/6/17 下午5:55
 **/
public class KfcService {

    /**
     * @MethodName getByOrderNo
     * @Description: 根据订单号查询订单详情
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/17 下午6:00
     */
    public static JSONObject getByOrderNo(Map<String , Object> map) throws Exception {
        
        JSONObject object = QianZhuService.request("/openApi/v1/kfcOrders/getByOrderNo" , map);
        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }
    }

    /**
     * @MethodName payKfcOrder
     * @Description:支付订单
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/17 下午6:07
     */
    public static JSONObject payKfcOrder(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/orders/payKfcOrder" , map);
        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }
    }

    /**
     * @MethodName listAll
     * @Description:查询KFC门店
     * @param map
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/17 下午6:10
     */
    public static JSONObject listAll(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v2/kfcStores/listAll" , map);
        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }
    }

    /**
     * @MethodName listByStoreCode
     * @Description:查询KFC门店菜单
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/17 下午6:11
     */
    public static JSONObject listByStoreCode(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v1/kfcMenus/listByStoreCode" , map);
        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }
    }

    /**
     * @MethodName createKfcOrder
     * @Description:创建kfc订单
     * @param map 
     * @return: com.alibaba.fastjson.JSONObject
     * @Author: Sum1Dream
     * @Date: 2024/6/17 下午6:12
     */
    public static JSONObject createKfcOrder(Map<String , Object> map) throws Exception {

        JSONObject object = QianZhuService.request("/openApi/v4/orders/createKfcOrder" , map);
        if (object.getBoolean("success") && object.getInteger("code") == 10000) {
            return object;
        } else {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "查询失败！");
        }
    }
}
