package com.hfkj.config.hsg;

import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.config.CommonSysConst;
import com.hfkj.model.UserDiscount;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: UserDiscountService
 * @author: HuRui
 * @date: 2022/11/24
 **/
public class UserDiscountService {

    // 请求域名地址
    private final static String reqUrl = CommonSysConst.getSysConfig().getHsg_domain_name();

    /**
     * 查询用户优惠券详情
     * @param userDiscountId
     * @return
     */
    public static UserDiscount getUserDiscountDetail(Long userDiscountId, String token) {
        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", token);

        Map<String, String> params = new HashMap<>();
        params.put("userDiscountId", userDiscountId.toString());

        JSONObject response = HttpsUtils.doGet(reqUrl + "/user/discount/getUserDiscountDetail", params, headers);
        if (response == null) {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求失败");
        }
        if (!response.getString("return_code").equals("000000")) {
            throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getString("return_msg"));
        }
        System.out.println(response);
        return response.getObject("return_data", UserDiscount.class);
    }


}
