import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { BszxGrade, BszxGradeParam } from './model';

/**
 * 分页查询百色中学-年级
 */
export async function pageBszxGrade(params: BszxGradeParam) {
  const res = await request.get<ApiResult<PageResult<BszxGrade>>>(
    '/bszx/bszx-grade/page',
    {
      params
    }
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询百色中学-年级列表
 */
export async function listBszxGrade(params?: BszxGradeParam) {
  const res = await request.get<ApiResult<BszxGrade[]>>(
    '/bszx/bszx-grade',
    {
      params
    }
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加百色中学-年级
 */
export async function addBszxGrade(data: BszxGrade) {
  const res = await request.post<ApiResult<unknown>>(
    '/bszx/bszx-grade',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改百色中学-年级
 */
export async function updateBszxGrade(data: BszxGrade) {
  const res = await request.put<ApiResult<unknown>>(
    '/bszx/bszx-grade',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

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

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

/**
 * 根据id查询百色中学-年级
 */
export async function getBszxGrade(id: number) {
  const res = await request.get<ApiResult<BszxGrade>>(
    '/bszx/bszx-grade/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
