/**
 * 会员管理API
 * @author pangu
 */
import request from '@/utils/request'

/**
 * 查询会员列表
 */
export function listMember(query) {
  return request({
    url: '/api/member/list',
    method: 'get',
    params: query
  })
}

/**
 * 获取会员详情
 */
export function getMember(id) {
  return request({
    url: `/api/member/${id}`,
    method: 'get'
  })
}

/**
 * 新增会员
 */
export function addMember(data) {
  return request({
    url: '/api/member',
    method: 'post',
    data
  })
}

/**
 * 修改会员
 */
export function updateMember(data) {
  return request({
    url: '/api/member',
    method: 'put',
    data
  })
}

/**
 * 删除会员
 */
export function deleteMember(id) {
  return request({
    url: `/api/member/${id}`,
    method: 'delete'
  })
}

/**
 * 重置会员密码
 */
export function resetMemberPwd(id) {
  return request({
    url: `/api/member/resetPwd/${id}`,
    method: 'put'
  })
}

/**
 * 修改会员状态
 */
export function changeMemberStatus(id, status) {
  return request({
    url: '/api/member/changeStatus',
    method: 'put',
    data: { memberId: id, status }
  })
}

/**
 * 绑定学生
 */
export function bindStudent(memberId, studentId) {
  return request({
    url: '/api/member/bindStudent',
    method: 'post',
    data: { memberId, studentId }
  })
}

/**
 * 解绑学生
 */
export function unbindStudent(memberId, studentId) {
  return request({
    url: `/api/member/unbindStudent/${memberId}/${studentId}`,
    method: 'delete'
  })
}

/**
 * 检查手机号唯一性
 */
export function checkPhoneUnique(phone, memberId) {
  return request({
    url: '/api/member/checkPhone',
    method: 'get',
    params: { phone, memberId }
  })
}

/**
 * 获取区域树
 */
export function getRegionTree() {
  return request({
    url: '/api/region/tree',
    method: 'get'
  })
}

/**
 * 获取学校列表（根据区域）
 */
export function getSchoolListByRegion(regionId) {
  return request({
    url: '/api/school/list',
    method: 'get',
    params: { regionId }
  })
}

/**
 * 获取年级列表（根据学校）
 */
export function getGradeListBySchool(schoolId) {
  return request({
    url: '/api/school/gradeList',
    method: 'get',
    params: { schoolId }
  })
}

/**
 * 获取班级列表（根据年级）
 */
export function getClassListByGrade(schoolGradeId) {
  return request({
    url: '/api/school/classList',
    method: 'get',
    params: { schoolGradeId }
  })
}

/**
 * 获取可绑定的学生列表
 */
export function getBindableStudents(query) {
  return request({
    url: '/api/student/bindableList',
    method: 'get',
    params: query
  })
}
