import APP from '@/services';
import { setSelectedAccount } from '@/services/bus/account';
import { getLongTypeLoginID } from "@/services/bus/login";
import { GetTaAccountsReq, QueryAmountLogReq, QueryAmountLogRsp, Taaccount } from "@/services/go/TaAccount/interface";
import { commonSearch_go } from "..";

/**
 *  获取资金账户信息
 */
export function getTaAccount() {
    const loginID = getLongTypeLoginID()?.toNumber()
    return commonSearch_go('/TaAccount/GetTaAccounts', { loginID }).then(res => {
        APP.set('accountList', res);
        if (res.length) {
            setSelectedAccount(res[0])
        }
        return 'ok'
    }).catch(err => { throw new Error(`获取资金账户信息失败：${err}`) })
}

/**
 * /TaAccount/QueryAmountLog
 * 资金流水查询（当前）
 * @param req
 */
export function queryAmountLog(req: QueryAmountLogReq): Promise<QueryAmountLogRsp> {
    return commonSearch_go('/TaAccount/QueryAmountLog', req).catch((err) => {
        throw new Error(`资金流水查询（当前）: ${err}`);
    });
}

/**
 * /TaAccount/GetTaAccounts
 * 获取资金账户信息
 * @param req
 */
export function getTaAccounts(req: GetTaAccountsReq): Promise<Taaccount> {
    return commonSearch_go('/TaAccount/GetTaAccounts', req).catch((err) => {
        throw new Error(`获取资金账户信息: ${err}`);
    });
}