import { getUserId } from "@/services/bus/account";
import { getAreaUserId, getUserAccountType } from "@/services/bus/user";
import { commonSearch_go } from '@/services/go';
import { Ermcp3AreaSpot, Ermcp3AreaSpotDetail, Ermcp3AreaSpotDetailReq, Ermcp3ExposureDetail, Ermcp3ExposureReq, ErmcpExposurePostion, ErmcpExposurePostionReq, ErmcpHedgePosition, ErmcpHedgePositionDetail, ErmcpHedgePositionDetailReq, ErmcpRealExposureModel } from '@/services/go/ermcp/exposure/interface';

/** ================================= 业务 - 敞口 ================================**/

/**
 * 请求实时敞口 (敞口 -> 实时敞口) /Ermcp/QueryRealtimeExposure
 * @constructor
 */
export function QueryActualExposure(): Promise<ErmcpRealExposureModel[]> {
    const userid = getUserId(); // 所属机构id
    const usertype = getUserAccountType()
    return commonSearch_go('/Ermcp/QueryRealtimeExposure', { userid, usertype}).catch((err) => {
        throw new Error(`查询敞口 -> 实时敞口: ${err}`);
    });
}

/**
 * 请求实时敞口现货明细信息 (敞口 ->实时敞口 -> 现货明细) /Ermcp3/QueryExposureDetail
 * @param req.middlegoodsid 套保商品
 * @constructor
 */
export function QueryActualExposureDetail(req: Ermcp3ExposureReq): Promise<Ermcp3ExposureDetail[]> {
    const userid = getAreaUserId(); // 用户id
    req.usertype = getUserAccountType()
    return commonSearch_go('/Ermcp3/QueryExposureDetail', { userid, ...req }).catch((err) => {
        throw new Error(`查询敞口 ->实时敞口 -> 现货明细: ${err}`);
    });
}

/**
 * 查询实时敞口期货头寸明细 (敞口 ->实时敞口 -> 期货明细) /Ermcp/QueryRealtimeExposurePosition
 * @param req.middleGoodsId 套保商品ID
 * @constructor
 */
export function QueryAutualExposurePosition(req: ErmcpExposurePostionReq): Promise<ErmcpExposurePostion[]> {
    const userid = getUserId(); // 所属机构id
    const usertype = getUserAccountType()
    return commonSearch_go('/Ermcp/QueryRealtimeExposurePosition', { userid, usertype, ...req }).catch((err) => {
        throw new Error(`查询敞口 ->实时敞口 -> 期货明细: ${err}`);
    });
}

/**
 * 请求敞口现货头寸 (敞口 -> 现货头寸) /Ermcp3/QueryExposureSpot
 * @constructor
 */
export function QuerySpotPosition(): Promise<Ermcp3AreaSpot[]> {
    const userid = getUserId(); // 用户id
    const usertype = getUserAccountType();  // 用户类型 2-机构 7-企业成员
    return commonSearch_go('/Ermcp3/QueryExposureSpot', { userid, usertype }).catch((err) => {
        throw new Error(`查询敞口 -> 现货头寸: ${err}`);
    });
}

/**
 * 查询敞口现货头寸明细(敞口 -> 现货头寸 -> 现货明细) /Ermcp3/QueryExposureSpotDetail
 * req.deliverygoodsid  现货品种ID
 * @constructor
 */
export function QuerySpotPositionDetail(req: Ermcp3AreaSpotDetailReq): Promise<Ermcp3AreaSpotDetail[]> {
    const userid = getUserId(); // 用户id
    const usertype = getUserAccountType();  // 用户类型 2-机构 7-企业成员
    return commonSearch_go('/Ermcp3/QueryExposureSpotDetail', { userid, usertype, ...req }).catch((err) => {
        throw new Error(`查询敞口 -> 现货头寸 -> 现货明细: ${err}`);
    });
}

/**
 * 查询敞口期货头寸(菜单:敞口-> 期货头寸) /Ermcp/QueryExposureHedgePosition
 * @constructor
 */
export function QueryExposureHedgePosition(): Promise<ErmcpHedgePosition[]> {
    const userid = getUserId(); // 所属机构id
    const usertype = getUserAccountType()
    return commonSearch_go('/Ermcp/QueryExposureHedgePosition', { userid, usertype }).catch((err) => {
        throw new Error(`查询敞口 -> 期货头寸: ${err}`);
    });
}

/**
 * 查询敞口期货头寸期货明细(菜单:敞口 -> 期货头寸 -> 期货明细) /Ermcp/QueryExposureHedgePositionDetail
 * @param req.goodsId  商品id
 * @constructor
 */
export function QueryExposureHedgePositionDetail(req: ErmcpHedgePositionDetailReq): Promise<ErmcpHedgePositionDetail[]> {
    const userid = getUserId(); // 所属机构id
    const usertype = getUserAccountType()
    return commonSearch_go('/Ermcp/QueryExposureHedgePositionDetail', { userid, usertype, ...req }).catch((err) => {
        throw new Error(`查询敞口->期货头寸->期货明细: ${err}`);
    });
}


