import http from '@/services/http'
import tradeServer from '@/services/socket/trade'
import { useAccountStore } from '@/stores'

const accountStore = useAccountStore()

/**
 * 银行签约
 */
export function t2bBankSign(params: Partial<Proto.t2bBankSignReq>) {
    return tradeServer.sendMessage<Proto.t2bBankSignRsp>({
        params,
        reqName: 't2bBankSignReq',
        rspName: 't2bBankSignRsp'
    })
}

/**
 * 银行解约
 */
export function t2bBankCancelSign(params: Proto.t2bBankCancelSignReq) {
    return tradeServer.sendMessage<Proto.t2bBankCancelSignRsp>({
        params,
        reqName: 't2bBankCancelSignReq',
        rspName: 't2bBankCancelSignRsp'
    })
}

/**
 * 出金申请
 */
export function t2bBankWithdraw(params: Partial<Proto.t2bBankWithdrawReq>) {
    return tradeServer.sendMessage<Proto.t2bBankWithdrawRsp>({
        params,
        reqName: 't2bBankWithdrawReq',
        rspName: 't2bBankWithdrawRsp'
    })
}

/**
 * 入金申请
 */
export function t2bBankDeposit(params: Partial<Proto.t2bBankDepositReq>) {
    return tradeServer.sendMessage<Proto.t2bBankDepositRsp>({
        params,
        reqName: 't2bBankDepositReq',
        rspName: 't2bBankDepositRsp'
    })
}

/**
 * 查询托管银行
 */
export function queryCusBankSignBank() {
    return http.commonRequest<Ermcp.CusBankSignBankRsp[]>({
        url: '/Qhj/QueryCusBankSignBank',
    })
}

/**
 * 查询开户行
 */
export function queryBankInfo() {
    return http.commonRequest<Ermcp.BankInfoRsp[]>({
        url: '/Qhj/QueryBankInfo',
    })
}

/**
 * 查询签约银行信息(提现账户管理)
 */
export function queryBankAccountSign(params: Ermcp.BankAccountSignReq) {
    return http.commonRequest<Ermcp.BankAccountSignRsp[]>({
        url: '/Qhj/QueryBankAccountSign',
        params,
    })
}

/**
 * 查询充值提现
 */
export function queryAccountInOutApply(params: Ermcp.AccountInOutApplyReq) {
    return http.commonRequest<Ermcp.AccountOutInApplyRsp[]>({
        url: '/Qhj/QueryAccountInOutApply',
        params,
    })
}

/**
 * 资金流水查询（当前）
 */
export function queryAmountLog(params: Ermcp.AmountLogReq) {
    return http.commonRequest<Ermcp.AmountLogRsp[]>({
        url: '/TaAccount/QueryAmountLog',
        params: {
            accountID: accountStore.accountId.toString(),
            pageflag: 1,
            ...params
        },
    })
}

/**
 * 资金流水查询（历史）
 */
export function queryHisAmountLog(params: Ermcp.HisAmountLogReq) {
    return http.commonRequest<Ermcp.HisAmountLogRsp[]>({
        url: '/TaAccount/QueryHisAmountLog',
        params: {
            accountID: accountStore.accountId.toString(),
            pageflag: 1,
            ...params
        },
    })
}