import { getUserId } from '@/services/bus/account';
import { getLongTypeLoginID } from '@/services/bus/login';
import { getAreaUserId } from "@/services/bus/user";
import {
    DeliveryGoodsApplyReq,
    DeliveryGoodsCancelReq, ErmcpSpotGoodsPriceReq,
    ErmsMiddelGoodsEditReq
} from "@/services/proto/delivery/interface";
import { protoMiddleware } from "@/services/socket/protobuf/buildReq";

/**
 * 现货品种申请请求
 * @param param DeliveryGoodsApplyReq
 */
export const addDeliveryGoodsApply = (param: DeliveryGoodsApplyReq): Promise<any> => {
    param.version = '3.2'
    param.userid = getUserId()
    param.loginid = Number(getLongTypeLoginID())
    return protoMiddleware<DeliveryGoodsApplyReq>(param, 'DeliveryGoodsApplyReq', 'DeliveryGoodsApplyRsp', 2)
}

/**
 * 修改套保品种请求 ErmsMiddelGoodsEditReq 只能修改比率 但是其它参数也必须传
 */
export const ermsMiddelGoodsEdit = (param: ErmsMiddelGoodsEditReq): Promise<any> => {
    param.areauserid = getAreaUserId() // 机构用户id
    return protoMiddleware<ErmsMiddelGoodsEditReq>(param, 'ErmsMiddelGoodsEditReq', 'ErmsMiddelGoodsEditRsp', 2)
}

/**
 * 现货品种停用请求
 */
export const deliveryGoodsCancel = (param: DeliveryGoodsCancelReq): Promise<any> => {
    return protoMiddleware<DeliveryGoodsCancelReq>(param, 'DeliveryGoodsCancelReq', 'DeliveryGoodsCancelRsp', 2)
}

/**
 * 修改现货市价
 * @param param
 */
export const ermcpSpotGoodsPrice = (param: ErmcpSpotGoodsPriceReq):Promise<any> => {
    return protoMiddleware<ErmcpSpotGoodsPriceReq>(param, 'ErmcpSpotGoodsPriceReq', 'ErmcpSpotGoodsPriceReq', 2)
}