import {
    TradeQueryParam,
    TradePageResult,
    WithDrawalsQueryParam,
    WithDrawalsPageResult,
    PassCoinParam,
    TradeDetail,
    PassCoinByOneParam,
    ChargeCoinParam,
    ChargeCoinPageResult,
} from "@/types/api/finance";
import request from "@/utils/request";
import { AxiosPromise } from "axios";

/**
 * "财务管理"=>"个人记录"
 * @param data
 */
export function perTradeAll(
    data: TradeQueryParam
): AxiosPromise<TradePageResult> {
    return request({
        url: "admin/finance/member-transaction/page-query",
        method: "post",
        params: data,
    });
}

/**
 * "财务管理"=>"提币管理(记录)"
 * @param data
 */
export function withdrawManage(
    data: WithDrawalsQueryParam
): AxiosPromise<WithDrawalsPageResult> {
    return request({
        url: "admin/finance/withdraw-record/page-query",
        method: "post",
        params: data,
    });
}

/**
 * "财务管理"=>"提币管理"   "一键通过"
 * @param data
 */
export function auditPass(ids: any): any {
    return request({
        url: "admin/finance/withdraw-record/audit-pass",
        method: "patch",
        params: ids,
    });
}

/**
 * "财务管理"=>"提币管理"   "一键不通过"
 * @param data
 */
export function auditNoPass(ids: any): any {
    return request({
        url: "admin/finance/withdraw-record/audit-no-pass",
        method: "patch",
        params: ids,
    });
}

/**
 * "财务管理" => "放币"
 * @param data
 */
export function passCoin(data: PassCoinParam): any {
    return request({
        url: "admin/finance/withdraw-record/remittance",
        method: "patch",
        data: data,
    });
}

/**
 * "审核详情"=>"个人交易详细信息"
 * @param data
 */
export function personalTradeInfo(data: any): AxiosPromise<TradeDetail> {
    return request({
        url: `admin/finance/withdraw-record/${data}`,
        method: "get",
    });
}

// 内部转账记录

export const transferPageQuery = (data: any) => {
    return request({
        url: "admin/finance/transfer/page-query",
        method: "post",
        params: data,
    });
};

/**
 * "财务管理" => "单个放币"
 * @param data
 */
export function passCoinByOne(data: PassCoinByOneParam): any {
    return request({
        url: "admin/finance/withdraw-record/add-transaction-number",
        method: "patch",
        params: data,
    });
}

/**
 * "财务管理"=>"充币明细"
 * @param data
 */
export function memberDeposit(
    data: ChargeCoinParam
): AxiosPromise<ChargeCoinPageResult> {
    return request({
        url: "admin/finance/member-deposit/page-query",
        method: "post",
        params: data,
    });
}

/**
 * "财务管理" => "提币总数"
 * @param data
 */
export function withdrawCount(): any {
    return request({
        url: "admin/finance/withdraw-record/count",
        method: "get",
    });
}

/**
 * 链上放币 Step1：生成签名参数
 */
export function chainApply(id: number): any {
    return request({
        url: `admin/finance/withdraw-record/chain-apply/${id}`,
        method: "post",
    });
}

/**
 * 链上放币 Step3：提交 txHash，后端验证并标记成功
 */
export function chainCallback(id: number, txHash: string): any {
    return request({
        url: "admin/finance/withdraw-record/chain-callback",
        method: "post",
        params: { id, txHash },
    });
}
