/**
 * 学生管理API
 * @author pangu
 */
import request from '@/utils/request'

// 查询学生列表
export function listStudent(query) {
  return request({
    url: '/api/student/list',
    method: 'get',
    params: query
  })
}

// 获取学生详情
export function getStudent(studentId) {
  return request({
    url: `/api/student/${studentId}`,
    method: 'get'
  })
}

// 新增学生
export function addStudent(data) {
  return request({
    url: '/api/student',
    method: 'post',
    data
  })
}

// 修改学生
export function updateStudent(data) {
  return request({
    url: '/api/student',
    method: 'put',
    data
  })
}

// 删除学生
export function deleteStudent(studentId) {
  return request({
    url: `/api/student/${studentId}`,
    method: 'delete'
  })
}

// 批量导入学生
export function importStudent(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/api/student/import',
    method: 'post',
    data: formData,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}

// 下载导入模板
export function downloadTemplate() {
  return request({
    url: '/api/student/template',
    method: 'get',
    responseType: 'blob'
  })
}

// 检查学号是否唯一
export function checkStudentNo(studentNo, studentId) {
  return request({
    url: '/api/student/checkStudentNo',
    method: 'get',
    params: { studentNo, studentId }
  })
}

// 获取会员列表（用于选择归属会员）
export function getMemberList(query) {
  return request({
    url: '/api/member/list',
    method: 'get',
    params: query
  })
}
