import {
  WithdrawChainConfigQueryParam,
  WithdrawChainConfigPageResult,
  WithdrawChainConfigFormData
} from '@/types/api/system/withdrawChainConfig';
import request from '@/utils/request';
import { AxiosPromise } from 'axios';

export function queryWithdrawChainConfig(data: WithdrawChainConfigQueryParam): AxiosPromise<WithdrawChainConfigPageResult> {
  return request({
    url: 'admin/system/withdraw-chain-config/page-query',
    method: 'post',
    params: data
  });
}

export function addWithdrawChainConfig(data: WithdrawChainConfigFormData): any {
  return request({
    url: 'admin/system/withdraw-chain-config/create',
    method: 'post',
    params: data
  });
}

export function updateWithdrawChainConfig(data: WithdrawChainConfigFormData): any {
  return request({
    url: 'admin/system/withdraw-chain-config/update',
    method: 'post',
    params: data
  });
}

export function deleteWithdrawChainConfig(id: number): any {
  return request({
    url: 'admin/system/withdraw-chain-config/delete',
    method: 'post',
    params: { id }
  });
}

/** 获取所有可用主网列表（用于下拉） */
export function getAllChainNames(): AxiosPromise<{ id: number; name: string }[]> {
  return request({
    url: 'admin/system/withdraw-chain-config/all-chain-names',
    method: 'post'
  });
}

/** 获取指定链下已配置的币种单位（联动下拉） */
export function getCoinUnitsByChain(
  chainName: string,
  includeCoinUnit?: string
): AxiosPromise<string[]> {
  return request({
    url: 'admin/system/withdraw-chain-config/coin-units-by-chain',
    method: 'post',
    params: { chainName, includeCoinUnit }
  });
}
