import { fetch, post } from '@/api/http'

export default {
  saveStudent: function(schoolId, data) {
    let format = {
      grant_type: 'create',
      schoolId: schoolId,
      students: []
    }
    format.students.push(...data)
    return post('/student/student-manage', format)
  },
  //��ѯѧ��
  findStudent: function(schoolId) {
    let format = {
      grant_type: 'read',
      schoolId: schoolId
    }
    return post('/student/student-manage', format)
  },
  saveAllStudent: function(schoolId, data) {
    let format = {
      grant_type: 'update',
      schoolId: schoolId,
      students: []
    }
    format.students.push(...data)
    return post('/student/student-manage', format)
  },
  /**
   * 刪除學生
   * @param {any} data
   */
  deleteStudent: function(schoolId, data) {
    let format = {
      grant_type: 'delete',
      schoolId: schoolId,
      students: []
    }
    format.students.push(...data)
    return post('/student/student-manage', format)
  },
  // 匯入
  ImportStudent: function(schoolId, data) {
    let format = {
      grant_type: 'import',
      schoolId: schoolId,
      students: []
    }
    format.students.push(...data)
    return post('/student/student-manage', format)
  },
  updateStudent: function(data) {
    return post('/api/Student/upsert', data)
  },
  updateAllStudent: function(data) {
    return post('/api/Student/upsertAll', data)
  },
  //取得AClassOne數目API
  getSchoolAclassOne: function(data) {
    return post('/school/init/get-school-aclassone', { school_code: data })
  },
  //設定固定AClassOne學生ID API
  setSchoolAclassOneState: function(data, studentIds) {
    return post('/school/init/set-school-aclasson-sta', {
      school_code: data,
      student_ids: studentIds //回傳預設定學生帳號的陣列，ex:["ID0001","ID0002","ID0003"]
    })
  },
  //回收AClassOne學生ID API
  recallSchoolAclassOne: function(data) {
    //※mode: 非必須，sta:回收固定  dync:回收動態
    return post('/school/init/recall-school-aclasson', {
      school_code: data
    })
  },
  //从班级移除学生
  removeStudent: function(data){
    return post('/student/student-manage', data)
  },
  //班级添加学生
  updateStudent: function(data){
    return post('/student/student-manage', data)
  }
}
