import request from '/@/utils/request'

/**
 * 毕业学生名单 - 分页查询
 * 接口文档：GET /api/stuwork/stugraducheck/page
 * 参数：current, size, graduYear, status, type, stuNo, realName, classCode, deptCode 等
 * 返回归一为 data.records / data.total 供 useTable 使用
 */
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
      }
    }
  })
}

/**
 * 学分确认
 * @param graduYear 毕业年份
 */
export const confirmScore = (graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/confirmScore',
    method: 'get',
    params: { graduYear }
  })
}

/**
 * 操行考核确认
 * @param graduYear 毕业年份
 */
export const confirmConduct = (graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/confirmConduct',
    method: 'get',
    params: { graduYear }
  })
}

/**
 * 违纪确认
 * @param graduYear 毕业年份
 */
export const confirmPunish = (graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/confirmPunish',
    method: 'get',
    params: { graduYear }
  })
}

/**
 * 等级工确认
 * @param graduYear 毕业年份
 */
export const confirmSkill = (graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/confirmSkill',
    method: 'get',
    params: { graduYear }
  })
}

/**
 * 固化学生操行考核数据到MongoDB
 * @param graduYear 毕业年份
 */
export const solidifyConduct = (graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/solidifyConduct',
    method: 'post',
    params: { graduYear }
  })
}

/**
 * 从MongoDB分页查询操行考核汇总数据
 * @param params 查询参数
 */
export const queryConductSummaryPage = (params: any) => {
  return request({
    url: '/stuwork/stugraducheck/conductSummaryPage',
    method: 'get',
    params
  })
}

/**
 * 固化学生学分数据到MongoDB
 * @param graduYear 毕业年份
 */
export const solidifyScore = (graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/solidifyScore',
    method: 'post',
    params: { graduYear }
  })
}

/**
 * 从MongoDB分页查询学分汇总数据
 * @param params 查询参数
 */
export const queryScoreSummaryPage = (params: any) => {
  return request({
    url: '/stuwork/stugraducheck/scoreSummaryPage',
    method: 'get',
    params
  })
}

// ========== 单个学生确认接口 ==========

/**
 * 单个学生学分确认详情
 * @param stuNo 学号
 * @param graduYear 毕业年份
 */
export const confirmScoreByStuNo = (stuNo: string, graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/confirmScoreByStuNo',
    method: 'get',
    params: { stuNo, graduYear }
  })
}

/**
 * 单个学生操行确认详情
 * @param stuNo 学号
 * @param graduYear 毕业年份
 */
export const confirmConductByStuNo = (stuNo: string, graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/confirmConductByStuNo',
    method: 'get',
    params: { stuNo, graduYear }
  })
}

/**
 * 单个学生违纪确认详情
 * @param stuNo 学号
 * @param graduYear 毕业年份
 */
export const confirmPunishByStuNo = (stuNo: string, graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/confirmPunishByStuNo',
    method: 'get',
    params: { stuNo, graduYear }
  })
}

/**
 * 单个学生等级工确认详情
 * @param stuNo 学号
 * @param graduYear 毕业年份
 */
export const confirmSkillByStuNo = (stuNo: string, graduYear: string) => {
  return request({
    url: '/stuwork/stugraducheck/confirmSkillByStuNo',
    method: 'get',
    params: { stuNo, graduYear }
  })
}
