import { request } from '@/service/request';

/** 获取学校详细信息列表 */
export function fetchGetSchoolDetailList(params?: Api.Art.SchoolDetailSearchParams) {
  return request<Api.Art.SchoolDetailList>({
    url: '/art/schoolDetail/list',
    method: 'get',
    params
  });
}

/** 根据学校ID获取学校详情信息（单条） */
export async function fetchGetSchoolDetailBySchoolId(schoolId: CommonType.IdType) {
  const result = await fetchGetSchoolDetailList({
    pageNum: 1,
    pageSize: 1,
    schoolId,
    params: {}
  });

  if (result.error) {
    return { ...result, data: null as Api.Art.SchoolDetail | null };
  }

  const detail = result.data.rows[0] ?? null;

  return {
    ...result,
    data: detail
  };
}
/** 新增学校详细信息 */
export function fetchCreateSchoolDetail(data: Api.Art.SchoolDetailOperateParams) {
  return request<boolean>({
    url: '/art/schoolDetail',
    method: 'post',
    data
  });
}

/** 修改学校详细信息 */
export function fetchUpdateSchoolDetail(data: Api.Art.SchoolDetailOperateParams) {
  return request<boolean>({
    url: '/art/schoolDetail',
    method: 'put',
    data
  });
}

/** 批量删除学校详细信息 */
export function fetchBatchDeleteSchoolDetail(detailIds: CommonType.IdType[]) {
  return request<boolean>({
    url: `/art/schoolDetail/${detailIds.join(',')}`,
    method: 'delete'
  });
}
