
/** ================================= 通用单据相关接口 ================================**/
import { getSelectedAccountId } from "@/services/bus/account";
import { commonSearch_go } from "@/services/go";
import {
    QueryHisTradeDetailReq,
    QueryHisTradeDetailRsp,
    QueryHisTradeOrderDetailReq,
    QueryHisTradeOrderDetailRsp,
    QueryTradeDetailReq,
    QueryTradeDetailRsp,
    QueryTradeOrderDetailReq, QueryTradeOrderDetailRsp, QueryTradePositionRsp
} from "@/services/go/ermcp/order/interface";

/**
 * 历史成交单查询（合约市场）
 * /Order/QueryHisTradeDetail
 * @param req
 */
export function queryHisTradeDetail(req: QueryHisTradeDetailReq): Promise<QueryHisTradeDetailRsp[]> {
    const accountID = getSelectedAccountId()?.toString()
    req.accountID = accountID
    return commonSearch_go('/Order/QueryHisTradeDetail', req).catch((err) => {
        throw new Error(`历史成交单查询（合约市场）: ${err}`);
    });
}

/**
 * 历史委托单查询请求（合约市场）
 * /Order/QueryHisTradeOrderDetail
 * @param req
 */
export function queryHisTradeOrderDetail(req: QueryHisTradeOrderDetailReq): Promise<QueryHisTradeOrderDetailRsp[]> {
    const accountID = getSelectedAccountId()?.toString()
    req.accountID = accountID
    return commonSearch_go('/Order/QueryHisTradeOrderDetail', req).catch((err) => {
        throw new Error(`历史委托单查询请求（合约市场）: ${err}`);
    });
}

/**
 * 成交单查询（合约市场）
 * /Order/QueryTradeDetail
 * @param req
 */
export function queryTradeDetail(req: QueryTradeDetailReq): Promise<QueryTradeDetailRsp[]> {
    const accountID = getSelectedAccountId()?.toString()
    req.accountID = accountID
    return commonSearch_go('/Order/QueryTradeDetail', req).catch((err) => {
        throw new Error(`成交单查询（合约市场）: ${err}`);
    });
}

/**
 * 委托单查询请求（合约市场）
 * /Order/QueryTradeOrderDetail
 * @param req
 */
export function queryTradeOrderDetail(req: QueryTradeOrderDetailReq): Promise<QueryTradeOrderDetailRsp[]> {
    const accountID = getSelectedAccountId()?.toString()
    req.accountID = accountID
    return commonSearch_go('/Order/QueryTradeOrderDetail', req).catch((err) => {
        throw new Error(`委托单查询请求（合约市场）: ${err}`);
    });
}

/**
 * 仓汇总查询（合约市场）
 * /Order/QueryTradePosition
 * @param //  交易模式 - 格式：1,2,3
 */
export function queryTradePosition(radeMode?: string): Promise<QueryTradePositionRsp[]> {
    const accountID = getSelectedAccountId()?.toString()
    const param = radeMode ? { accountID, radeMode } : { accountID }
    return commonSearch_go('/Order/QueryTradePosition', param).catch((err) => {
        throw new Error(`仓汇总查询（合约市场）: ${err}`);
    });
}




