import APP from '@/services';
import { buildProtoReq50, parseProtoRsp50 } from '@/services/socket/protobuf/buildReq';
import { Callback } from '@/utils/websocket/index';

/**
 * 查询系统参数
 */
export function querySystemParam(): Promise<string> {
    return new Promise((resolve, reject) => {
        const params = {
            protobufName: 'ConfigQueryReq',
            funCodeName: 'ConfigQueryReq',
            reqParams: { configUTime: APP.get('lastUpdateTime').configUTime },
        };
        const package50 = buildProtoReq50(params);
        APP.sendTradingServer(package50, undefined, {
            onSuccess: (res) => {
                const { isSuccess, result } = parseProtoRsp50(res, 'ConfigQueryRsp');
                if (isSuccess) {
                    APP.set('ssystemParam', result.ConfigInfoList);
                    resolve('ok');
                } else {
                    reject(result);
                }
            },
            onFail: (err) => reject(err.message),
        } as Callback);
    });
}
/**
 * funcode查找错误码
 */
export function queryErrorCode(): Promise<string> {
    return new Promise((resolve, reject) => {
        const params = {
            protobufName: 'ErrorCodeQueryReq',
            funCodeName: 'ErrorCodeQueryReq',
            reqParams: { errorcodeUTime: APP.get('lastUpdateTime').errorcodeUTime },
        };
        const package50 = buildProtoReq50(params);
        APP.sendTradingServer(package50, undefined, {
            onSuccess: (res) => {
                const { isSuccess, result } = parseProtoRsp50(res, 'ErrorCodeQueryRsp');
                if (isSuccess) {
                    // APP.set('errorCodeList', result.ErrorCodeList);
                    resolve('ok');
                } else {
                    reject(result);
                }
            },
            onFail: (err) => reject(err.message),
        } as Callback);
    });
}
