/** ================================= 现货合同 ================================**/
import { getUserId } from "@/services/bus/account";
import { commonSearch_go } from '@/services/go';
import {
    Ermcp3ContractReq,
    Ermcp3ContractRsp,
    ErmcpOPLogModel,
    QueryChangeLogReq
} from '@/services/go/ermcp/spot-contract/interface';
import {getUserAccountType} from "@/services/bus/user";

/**
 * 查询现货合同 /Ermcp3/QuerySpotContract
 * @param req.querytype 查询类型 1-未提交 2-待审核 3-履约中 4-已完成
 * @param req.userid 用户ID (非必填)
 * @param req.usertype 用户类型 2-机构 7-企业成员 (非必填)
 * @param req.contractid 合同ID(SpotContractId) (非必填)
 * @constructor
 */
export function QuerySpotContract(req: Ermcp3ContractReq): Promise<Ermcp3ContractRsp[]> {
    const userid = getUserId(); // 所属机构id
    // const areauserid = 10000; // 所属机构id
    req.usertype = getUserAccountType()
    return commonSearch_go('/Ermcp3/QuerySpotContract', { userid, ...req }).catch((err) => {
        throw new Error(`查询现货合同: ${err}`);
    });
}

/**
 * 查询变更记录 /Ermcp/QueryChangeLog
 * @param req
 * @constructor
 */
export function QueryChangeLog(req: QueryChangeLogReq): Promise<ErmcpOPLogModel[]> {
    return commonSearch_go('/Ermcp/QueryChangeLog', req).catch((err) => {
        throw new Error(`查询变更记录: ${err}`);
    });
}

