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

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

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

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

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

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

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

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

/**
 * 查询应用-百色中学-班级列表
 */
export async function getBszxClassForTree() {
  const res = await request.get<ApiResult<BszxClass[]>>(
    '/bszx/bszx-class/tree'
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}


