import request from '/@/utils/request'

/**
 * 分页查询毕业学生（毕业审核列表）
 * 后端返回 data.dataList.records / data.dataList.total，此处归一为 data.records / data.total 供 useTable 使用
 * @param query current, size, graduYear, status, type, stuNo, realName, classCode, deptCode, ...
 */
export const fetchList = (query?: any) => {
  return request({
    url: '/stuwork/stugraducheck/page',
    method: 'get',
    params: query
  }).then((res: any) => {
    const raw = res.data || {}
    const dataList = raw.dataList || {}
    return {
      ...res,
      data: {
        records: dataList.records || [],
        total: dataList.total ?? 0,
        canExamConduct: raw.canExamConduct,
        canExamScore: raw.canExamScore,
        canExamSkill: raw.canExamSkill,
        canExamStuPunish: raw.canExamStuPunish,
        canExamBaseInfo: raw.canExamBaseInfo
      }
    }
  })
}

/**
 * 生成毕业生信息
 * @param data 如 { type: '0' }
 */
export const makeGraduStu = (data?: { type?: string }) => {
  return request({
    url: '/stuwork/stugraducheck/makeGraduStu',
    method: 'post',
    data: data || { type: '0' }
  })
}

/**
 * 获取某年毕业生列表（用于统计页前端汇总，大 size 拉取）
 * @param graduYear 毕业年份
 */
export const fetchListForAnalyse = (graduYear: string | number) => {
  return request({
    url: '/stuwork/stugraducheck/page',
    method: 'get',
    params: {
      graduYear,
      current: 1,
      size: 9999
    }
  }).then((res: any) => {
    const raw = res.data || {}
    const dataList = raw.dataList || {}
    return (dataList.records || []) as any[]
  })
}
