import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  AirdropDistributeForm,
  AirdropRecordItem,
  BatchAirdropDistributeRequest,
  BatchAirdropDistributeResult,
  PageQueryParam,
  PageResult,
  StakingOrderQueryParam,
  StakingConfigItem,
  StakingOrderItem,
  StakingRecordItem
} from '@/types/api/staking/index';

export function listStakingConfigs(): AxiosPromise<StakingConfigItem[]> {
  return request({ url: 'admin/staking/config/list', method: 'post' });
}

export function addStakingConfig(data: StakingConfigItem): AxiosPromise<StakingConfigItem> {
  return request({ url: 'admin/staking/config/add', method: 'post', data });
}

export function updateStakingConfig(data: StakingConfigItem): AxiosPromise<StakingConfigItem> {
  return request({ url: 'admin/staking/config/update', method: 'post', data });
}

export function listStakingOrders(data: StakingOrderQueryParam): AxiosPromise<PageResult<StakingOrderItem>> {
  return request({ url: 'admin/staking/orders', method: 'post', params: data });
}

/** 对质押中订单发放空投 */
export function distributeAirdropForOrder(data: AirdropDistributeForm): AxiosPromise<unknown> {
  return request({ url: 'admin/staking/orders/airdrop-distribute', method: 'post', data });
}

export function batchDistributeAirdropForOrders(
  data: BatchAirdropDistributeRequest
): AxiosPromise<BatchAirdropDistributeResult> {
  return request({ url: 'admin/staking/orders/airdrop-distribute/batch', method: 'post', data });
}

export function listStakingRecords(data: PageQueryParam): AxiosPromise<PageResult<StakingRecordItem>> {
  return request({ url: 'admin/staking/records', method: 'post', params: data });
}

/** 管理员向指定用户分配空投 */
export function distributeAirdrop(data: AirdropDistributeForm): AxiosPromise<unknown> {
  return request({ url: 'admin/airdrop/distribute', method: 'post', data });
}

export function listAirdropRecords(
  data: PageQueryParam & { status?: number }
): AxiosPromise<PageResult<AirdropRecordItem>> {
  return request({ url: 'admin/airdrop/records', method: 'post', params: data });
}

/** 待审核空投申请列表（status=2） */
export function listAirdropAudit(data: PageQueryParam): AxiosPromise<PageResult<AirdropRecordItem>> {
  return request({ url: 'admin/airdrop/audit/list', method: 'post', params: data });
}

/** 审核通过 */
export function approveAirdropAudit(id: number): AxiosPromise<unknown> {
  return request({ url: `admin/airdrop/audit/approve/${id}`, method: 'post' });
}

/** 审核拒绝 */
export function rejectAirdropAudit(id: number, remark?: string): AxiosPromise<unknown> {
  return request({ url: `admin/airdrop/audit/reject/${id}`, method: 'post', params: { remark } });
}
