import { getUserId } from "@/services/bus/account";
import { getLongTypeLoginID } from "@/services/bus/login";
import {
    AreaInOutApplyAuditPassReq, AuditERMCPAreaInOutStockApplyReq, ERMCPAreaInOutStockApplyReq,
    WarehouseApplyReq,
    WarehouseStateChangeReq
} from "@/services/proto/warehouse/interface";
import { protoMiddleware } from "@/services/socket/protobuf/buildReq";
import { getUUID } from "@/utils/qt/common";

/**
 * 新增 / 修改 仓库信息请求  修改需要传仓库id
 * @param param.type (必填)   类型 1 新增 2 修改
 * @param param.warehousecode (必填)   仓库代码
 * @param param.warehousename (必填)   仓库名称
 * @param param.warehousetype (必填)   仓库类型
 */
export const addWarehouseApply = (param: WarehouseApplyReq): Promise<any> => {
    const userid = getUserId();
    Object.assign(param, { userid },)
    return protoMiddleware<WarehouseApplyReq>(param, 'WarehouseApplyReq', 'WarehouseApplyRsp', 2)
}

/**
 * 仓库状态修改请求
 * @param param.warehouseid  仓库ID
 * @param param.warehousestatus 仓库状态 - 1:正常 2:注销 3:待审核 4:审核拒绝
 */
export const warehouseStateChangeReq = (param: WarehouseStateChangeReq): Promise<any> => {
    return protoMiddleware<WarehouseStateChangeReq>(param, 'WarehouseStateChangeReq', 'WarehouseStateChangeRsp', 2)
}

/**
 * 出入库审核 审核通过
 * @param param
 */
export const inOutStockApplyReq = (param: AreaInOutApplyAuditPassReq): Promise<any> => {
    param.ClientTicket = getUUID()
    param.AuditSrc = 2
    return protoMiddleware<AreaInOutApplyAuditPassReq>(param, 'AreaInOutApplyAuditPassReq', 'AreaInOutApplyAuditPassRsp', 2)
}

/**
 * 出入库审核 审核拒绝 & 撤回
 * @param param
 */
export const refuseStockApplyReq = (param: AuditERMCPAreaInOutStockApplyReq): Promise<any> => {
    return protoMiddleware<AuditERMCPAreaInOutStockApplyReq>(param, 'AuditERMCPAreaInOutStockApplyReq', 'AuditERMCPAreaInOutStockApplyRsp', 2)
}

/**
 * 出入库申请
 * @param param
 */
export const ermcpInOutStockApplyReq = (param: ERMCPAreaInOutStockApplyReq): Promise<any> => {
    param.UserID = getUserId()
    param.ApplySrc = 2
    param.ApplyId = Number(getLongTypeLoginID())
    return protoMiddleware<ERMCPAreaInOutStockApplyReq>(param, 'ERMCPAreaInOutStockApplyReq', 'ERMCPAreaInOutStockApplyRsp', 2)
}