import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type {BszxPay, BszxPayParam} from "@/api/bszx/bszxPay/model";
import type {BszxBm,BszxBmParam} from "@/api/bszx/bszxBm/model";

/**
 * 分页查询百色中学-捐款记录
 */
export async function pageBszxPay(params: BszxPayParam) {
  const res = await request.get<ApiResult<PageResult<BszxPay>>>(
    '/bszx/bszx-pay/page',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询百色中学-捐款记录列表
 */
export async function listBszxPay(params?: BszxPayParam) {
  const res = await request.get<ApiResult<BszxPay[]>>(
    '/bszx/bszx-pay',
    {
      params
    }
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加百色中学-捐款记录
 */
export async function addBszxPay(data: BszxPay) {
  const res = await request.post<ApiResult<BszxPay>>(
    '/bszx/bszx-pay',
    data
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改百色中学-捐款记录
 */
export async function updateBszxPay(data: BszxPay) {
  const res = await request.put<ApiResult<unknown>>(
    '/bszx/bszx-pay',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除百色中学-捐款记录
 */
export async function removeBszxPay(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/bszx/bszx-pay/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除百色中学-捐款记录
 */
export async function removeBatchBszxPay(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/bszx/bszx-pay/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询百色中学-捐款记录
 */
export async function getBszxPay(id: number) {
  const res = await request.get<ApiResult<BszxPay>>(
    '/bszx/bszx-pay/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}


/**
 * 查询应用-百色中学-报名记录列表
 */
export async function myPageBszxPay(params?: BszxBmParam) {
  const res = await request.get<ApiResult<PageResult<BszxBm>>>(
    '/bszx/bszx-pay/myPage',
    params
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
export async function getPayCert(id: number) {
  const res = await request.get<ApiResult<BszxBm>>(
    '/bszx/bszx-pay/generatePayCert/' + id, {}
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

export async function getCount() {
  const res = await request.get<ApiResult<any>>(
    '/bszx/bszx-pay/getCount'
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
