import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api/index';
import type { BszxBm, BszxBmParam } from './model';

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

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

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

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

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

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

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

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

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