import request from "@/utils/request";
function customParamsSerializer(params) {
  let result = '';
  for (let key in params) {
    if (params.hasOwnProperty(key)) {
      if (Array.isArray(params[key])) {
        params[key].forEach((item,index) => {
          if(item.key){
            result += `${key}[${index}][key]=${item.key}&${key}[${index}][op]=${item.op}&${key}[${index}][value]=${item.value}&`;

          }else{
            result +=`${key}[${index}]=${item}&`
          }
        });
      } else {
        result += `${key}=${params[key]}&`;
      }
    }
  }
  return result.slice(0, -1);
}

export function index(params,isLoading = false) {
  return request({
    method: "get",
    url: "/api/admin/users/index",
    params,
    paramsSerializer: customParamsSerializer,
    isLoading
  })
}

export function indexStudy(params,isLoading = false) {
  return request({
    method: "get",
    url: "/api/admin/users/study",
    params,
    paramsSerializer: customParamsSerializer,
    isLoading
  })
}

export function show(params, isLoading = true) {
  return request({
    method: "get",
    url: "/api/admin/users/show",
    params,
    isLoading
  })
}


export function save(data) {
  return request({
    method: "post",
    url: "/api/admin/users/save",
    data
  })
}

export function destroy(params) {
  return request({
    method: "get",
    url: "/api/admin/users/destroy",
    params
  })
}

export function importStudy(data) {
  return request({
    method: "post",
    url: "/api/admin/users/import-study",
    data
  })
}

export function updateSchoolmate(data) {
  return request({
    method: "post",
    url: "/api/admin/users/batch-update-schoolmate",
    data
  })
}


