package com.nokia.domainb.capability;

import cn.chinaunicom.open.common.Const;
import cn.chinaunicom.open.nlgxptconnection.COMPConnection;
import cn.chinaunicom.open.nlgxptconnection.COMPConnectionContext;
import cn.chinaunicom.open.nlgxptconnection.impl.COMPJsonConnection;

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

/**
 * 已订购产品查询
 * json_microservice_users_foreignproduct
 */
public class Foreignproduct extends AbstractQuery {
    private static final String url = "http://192.168.70.130:8000/api/microservice/users/foreignproduct/v1";
    // private static final String url = "http://10.245.34.209:8000/api/microservice/users/foreignproduct/v1";
    private static final String urlTest = "http://10.124.150.230:8000/api/microservice/users/foreignproduct/v1";

    public COMPConnectionContext query(String phoneNumber, String provinceCode, boolean test) {
        String realAppSecret = test ? appSecretTest : appSecret;
        String realUrl = test ? urlTest : url;
        COMPConnection compConnection = new COMPJsonConnection(appId, realAppSecret);

        // REQ
        Map<String, Object> req = new HashMap<>();

        Map<String, Object> foreignProductReq = new HashMap<>();
        req.put("FOREIGN_PRODUCT_REQ", foreignProductReq);
        foreignProductReq.put("APPKEY", "hbltywts");
        foreignProductReq.put("APPTX", appId);

        Map<String, Object> msg = new HashMap<>();
        foreignProductReq.put("MSG", msg);
        msg.put("number", phoneNumber);
        msg.put("province", provinceCode);

        // Map<String, Object> para = new HashMap<>();
        // msg.put("para", para);
        msg.put("city", "188");
        msg.put("district", "123");
        msg.put("channelType", "18zzzzz");
        // 查询类型 P-产品（查询用户产品，返回数据中包信息以及元素信息为空） K-包（查询用户产品以及产品下面的包，返回数据中元素信息为空）
        // S-服务（查询用户的服务） D-优惠（查询用户的优惠） A-所有（查询产品、包、服务、优惠信息）
        msg.put("qryType", "A");
        msg.put("operatorId", "v-wangyl5740-1");
        msg.put("channelId", "18zzzzz");

        COMPConnectionContext context = compConnection.excute(Const.HttpMethodType.POST, realUrl, req, false);
        return context;
    }

}
