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
  });
}

/** 获取满意度明细JSON */
export function fetchGetSchoolDetailSatisfactionJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailSatisfactionPayload>({
    url: '/art/schoolDetail/json/satisfaction',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新满意度明细JSON */
export function fetchUpdateSchoolDetailSatisfactionJson(data: Api.Art.SchoolDetailSatisfactionPayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/satisfaction',
    method: 'put',
    data
  });
}

/** 获取奖学金JSON */
export function fetchGetSchoolDetailScholarshipJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailScholarshipPayload>({
    url: '/art/schoolDetail/json/scholarship',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新奖学金JSON */
export function fetchUpdateSchoolDetailScholarshipJson(data: Api.Art.SchoolDetailScholarshipPayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/scholarship',
    method: 'put',
    data
  });
}

/** 获取特色专业JSON */
export function fetchGetSchoolDetailSpecialMajorJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailSpecialMajorPayload>({
    url: '/art/schoolDetail/json/specialMajor',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新特色专业JSON */
export function fetchUpdateSchoolDetailSpecialMajorJson(data: Api.Art.SchoolDetailSpecialMajorPayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/specialMajor',
    method: 'put',
    data
  });
}

/** 获取就业报告JSON */
export function fetchGetSchoolDetailEmploymentReportJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailEmploymentReportPayload>({
    url: '/art/schoolDetail/json/employmentReport',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新就业报告JSON */
export function fetchUpdateSchoolDetailEmploymentReportJson(data: Api.Art.SchoolDetailEmploymentReportPayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/employmentReport',
    method: 'put',
    data
  });
}

/** 获取学校图片JSON */
export function fetchGetSchoolDetailPhotoJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailPhotoPayload>({
    url: '/art/schoolDetail/json/photo',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新学校图片JSON */
export function fetchUpdateSchoolDetailPhotoJson(data: Api.Art.SchoolDetailPhotoPayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/photo',
    method: 'put',
    data
  });
}

/** 获取建筑配套JSON */
export function fetchGetSchoolDetailAccommodationJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailAccommodationPayload>({
    url: '/art/schoolDetail/json/accommodation',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新建筑配套JSON */
export function fetchUpdateSchoolDetailAccommodationJson(data: Api.Art.SchoolDetailAccommodationPayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/accommodation',
    method: 'put',
    data
  });
}

/** 获取学科评估JSON */
export function fetchGetSchoolDetailSubjectReviewsJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailSubjectReviewsPayload>({
    url: '/art/schoolDetail/json/subjectReviews',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新学科评估JSON */
export function fetchUpdateSchoolDetailSubjectReviewsJson(data: Api.Art.SchoolDetailSubjectReviewsPayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/subjectReviews',
    method: 'put',
    data
  });
}

/** 获取科研信息JSON */
export function fetchGetSchoolDetailResearchJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailResearchPayload>({
    url: '/art/schoolDetail/json/research',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新科研信息JSON */
export function fetchUpdateSchoolDetailResearchJson(data: Api.Art.SchoolDetailResearchPayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/research',
    method: 'put',
    data
  });
}

/** 获取专业标签JSON */
export function fetchGetSchoolDetailUnivMajorsJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailUnivMajorsPayload>({
    url: '/art/schoolDetail/json/univMajors',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新专业标签JSON */
export function fetchUpdateSchoolDetailUnivMajorsJson(data: Api.Art.SchoolDetailUnivMajorsPayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/univMajors',
    method: 'put',
    data
  });
}

/** 获取保研信息JSON */
export function fetchGetSchoolDetailUnivPostgraduateJson(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailUnivPostgraduatePayload>({
    url: '/art/schoolDetail/json/univPostgraduate',
    method: 'get',
    params: { schoolId }
  });
}

/** 更新保研信息JSON */
export function fetchUpdateSchoolDetailUnivPostgraduateJson(data: Api.Art.SchoolDetailUnivPostgraduatePayload) {
  return request<boolean>({
    url: '/art/schoolDetail/json/univPostgraduate',
    method: 'put',
    data
  });
}

/** 获取院校详情JSONB全量 */
export function fetchGetSchoolDetailJsonAll(schoolId: CommonType.IdType) {
  return request<Api.Art.SchoolDetailJsonAllPayload>({
    url: '/art/schoolDetail/json/all',
    method: 'get',
    params: { schoolId }
  });
}

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