import { getUserId } from "@/services/bus/user";
import { commonSearch_go } from '@/services/go/index';
import {
    Ermcp8RunningHedgeditemReq,
    Ermcp2HedgedItemReq,
    Ermcp2HedgedItemRsp,
    ERMCPJRLinkPosReq,
    ERMCPJRLinkPosRsp,
    ERMCP2HedgedItemspotReq,
    ERMCP2HedgedItemspotRsp,
    ERMCP2HedgedItemSpotDetailReq,
    ERMCP2HedgedItemSpotDetailRsp,
    ERMCPPatradeLinkDetailReq,
    ERMCPPatradeLinkDetailRsp,
    InternalUncorrelatedTradeDetailReq,
    InternalUncorrelatedTradeDetailRsp,
    InternalEnableTradeDetailReq,
    InternalEnableTradeDetailRsp,
    UnLinkSpotContractReq,
    UnLinkSpotContractRsp,
    Ermcp8EnableHedgeditemReq,
    Ermcp8EnableHedgeditemRsp,
    Ermcp2AreaExposureReq,
    Ermcp2AreaExposureRsp,
    Ermcp2StockSpotChangeLogReq,
    Ermcp2StockSpotChangeLogRsp,
    Ermcp2HedgedItemsDetailReq,
    Ermcp2HedgedItemsDetailRsp,
    PatradeLinkDetailReq,
    PatradeLinkDetailRsp,
    UnLinkErmcpHedgePlanReq,
    UnLinkErmcpHedgePlanRsp,
} from './interface'

/**
 * 查询执行中项目查询信息
 * @param req 
 * @returns 
 */
export function queryErmcp8RunningHedgeditem(req: Ermcp8RunningHedgeditemReq): Promise<Ermcp2HedgedItemRsp[]> {
    req.userid = getUserId();
    return commonSearch_go('/Ermcp8/QueryErmcp8RunningHedgeditem', req).catch((err) => {
        throw new Error(`
        查询执行中项目查询信息: ${err}`);
    })
}

/**
 * 查询被套期项目信息
 * @param req 
 * @returns 
 */
export function queryErmcp2HedgedItem(req: Ermcp2HedgedItemReq): Promise<Ermcp2HedgedItemRsp[]> {
    req.userid = getUserId();
    return commonSearch_go('/Ermcp8/QueryErmcp2HedgedItem', req).catch((err) => {
        throw new Error(`查询被套期项目信息: ${err}`);
    })
}

/**
 * 期货持仓明细查询
 * @param req 
 * @returns 
 */
export function queryERMCPJRLinkPos(req: ERMCPJRLinkPosReq): Promise<ERMCPJRLinkPosRsp[]> {
    return commonSearch_go('/Ermcp8/QueryERMCPJRLinkPos', req).catch((err) => {
        throw new Error(`期货持仓明细查询: ${err}`);
    })
}

/**
 * 套期计划明细查询
 * @param req 
 * @returns 
 */
export function queryERMCP2HedgedItemspot(req: ERMCP2HedgedItemspotReq): Promise<ERMCP2HedgedItemspotRsp[]> {
    return commonSearch_go('/Ermcp8/QueryERMCP2HedgedItemspot', req).catch((err) => {
        throw new Error(`套期计划明细查询: ${err}`);
    })
}

/**
 * 现货成交明细查询
 * @param req 
 * @returns 
 */
export function queryERMCP2HedgedItemSpotDetail(req: ERMCP2HedgedItemSpotDetailReq): Promise<ERMCP2HedgedItemSpotDetailRsp[]> {
    return commonSearch_go('/Ermcp8/QueryERMCP2HedgedItemSpotDetail', req).catch((err) => {
        throw new Error(`现货成交明细查询: ${err}`);
    })
}

/**
 * 期货成交单明细查询
 * @param req 
 * @returns 
 */
export function queryERMCPPatradeLinkDetail(req: ERMCPPatradeLinkDetailReq): Promise<ERMCPPatradeLinkDetailRsp[]> {
    return commonSearch_go('/Ermcp8/QueryERMCPPatradeLinkDetail', req).catch((err) => {
        throw new Error(`期货成交单明细查询: ${err}`);
    })
}

/**
 * 内部未关联成交单查询
 * @param req 
 * @returns 
 */
export function queryInternalUncorrelatedTradeDetail(req: InternalUncorrelatedTradeDetailReq): Promise<InternalUncorrelatedTradeDetailRsp[]> {
    return commonSearch_go('/Ermcp8/QueryInternalUncorrelatedTradeDetail', req).catch((err) => {
        throw new Error(`内部未关联成交单查询: ${err}`);
    })
}

/**
 * 内部成交单可关联项目查询
 * @param req 
 * @returns 
 */
export function queryInternalEnableTradeDetail(req: InternalEnableTradeDetailReq): Promise<InternalEnableTradeDetailRsp[]> {
    return commonSearch_go('/Ermcp8/QueryInternalEnableTradeDetail', req).catch((err) => {
        throw new Error(`内部未关联成交单查询: ${err}`);
    })
}

/**
 * 未关联合同查询
 * @param req 
 * @returns 
 */
export function queryUnLinkSpotContract(req: UnLinkSpotContractReq): Promise<UnLinkSpotContractRsp[]> {
    return commonSearch_go('/Ermcp8/QueryUnLinkSpotContract', req).catch((err) => {
        throw new Error(`未关联合同查询: ${err}`);
    })
}


/**
 * 未关联购销计划
 * @param req 
 * @returns 
 */
export function queryUnLinkErmcpHedgePlan(req: UnLinkErmcpHedgePlanReq): Promise<UnLinkErmcpHedgePlanRsp[]> {
    return commonSearch_go('/Ermcp8/QueryUnLinkErmcpHedgePlan', req).catch((err) => {
        throw new Error(`未关联购销计划: ${err}`);
    })
}

/**
 * 可关联项目查询
 * @param req 
 * @returns 
 */
export function queryErmcp8EnableHedgeditem(req: Ermcp8EnableHedgeditemReq): Promise<Ermcp8EnableHedgeditemRsp[]> {
    return commonSearch_go('/Ermcp8/QueryErmcp8EnableHedgeditem', req).catch((err) => {
        throw new Error(`可关联项目查询: ${err}`);
    })
}

/**
 * 企业敞口查询
 * @param req 
 * @returns 
 */
export function queryErmcp2AreaExposure(req: Ermcp2AreaExposureReq): Promise<Ermcp2AreaExposureRsp[]> {
    return commonSearch_go('/Ermcp8/QueryErmcp2AreaExposure', req).catch((err) => {
        throw new Error(`企业敞口查询: ${err}`);
    })
}

/**
 * 敞口明细 - 现货变动明细查询
 * @param req 
 * @returns 
 */
export function queryErmcp2StockSpotChangeLog(req: Ermcp2StockSpotChangeLogReq): Promise<Ermcp2StockSpotChangeLogRsp[]> {
    return commonSearch_go('/Ermcp8/QueryErmcp2StockSpotChangeLog', req).catch((err) => {
        throw new Error(`敞口明细 - 现货变动明细查询: ${err}`);
    })
}

/**
 * 敞口明细 - 计划变动明细
 * @param req 
 * @returns 
 */
export function queryErmcp2HedgedItemsDetail(req: Ermcp2HedgedItemsDetailReq): Promise<Ermcp2HedgedItemsDetailRsp[]> {
    return commonSearch_go('/Ermcp8/QueryErmcp2HedgedItemsDetail', req).catch((err) => {
        throw new Error(`敞口明细 - 计划变动明细: ${err}`);
    })
}

/**
 * 敞口明细 - 期货变动明细
 * @param req 
 * @returns 
 */
export function queryPatradeLinkDetail(req: PatradeLinkDetailReq): Promise<PatradeLinkDetailRsp[]> {
    return commonSearch_go('/Ermcp8/QueryPatradeLinkDetail', req).catch((err) => {
        throw new Error(`敞口明细 - 期货变动明细: ${err}`);
    })
}