import {http2} from "@/utils/request.js";

/** 获取所有服务器 */
export const getServer = (page, count, key, type = "dockerContainer") => {
  return http2.get(
    `/acs/v1/admin/server/get_server_list?page=${page}&count=${count}&key=${key}&server_type=${type}`
  );
};

/**新增服务器 */
export const addServer = data => {
  return http2.post("/acs/v1/admin/server/add_server", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**编辑服务器 */
export const editServer = data => {
  return http2.post("/acs/v1/admin/server/update_server", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**删除服务器 */
export const deleteServer = data => {
  return http2.post("/acs/v1/admin/server/delete_server", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**查询指定服务器 */
export const selectServer = data => {
  return http2.post("/acs/v1/admin/server/select_server", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取服务器套餐列表*/
export const getServerPlan = data => {
  return http2.get(
    `/acs/v1/admin/container_plan/get_server_plan_list?server_id=${data.server_id}&count=${data.count}`
  );
};
/**获取指定套餐 */
export const selectServerPlan = data => {
  return http2.post("/acs/v1/admin/container_plan/get_server_plan_detail", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**新增容器 */
export const addContainer = data => {
  return http2.post("/acs/v1/admin/container/add_container", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**删除容器网络 */
export const deleteContainerNetwork = data => {
  return http2.post("/acs/v1/user/container/delete_connect", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**修改套餐信息 */
export const editServerPlan = data => {
  return http2.post("/acs/v1/admin/container_plan/update_server_plan", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**新增套餐 */
export const addServerPlan = data => {
  return http2.post("/acs/v1/admin/container_plan/add_server_plan", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**删除套餐 */
export const deleteServerPlan = data => {
  return http2.post("/acs/v1/admin/container_plan/delete_server_plan", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取容器列表 */
export const getContainer = data => {
  return http2.get(
    `/acs/v1/admin/container/get_container_list?server_id=${data.server_id}&user_id=${data.user_id}&page=${data.page}&count=${data.count}&key=${data.key}`
  );
};

/**获取虚拟机列表 */
export const getInstanceList = data => {
  return http2.get(
    `/acs/v1/admin/instance/list?server_id=${data.server_id}&user_id=${data.user_id}&page=${data.page}&count=${data.count}&key=${data.key}`
  );
};
/**获取单个指定容器 */
export const getOneContainer = data => {
  return http2.post("/acs/v1/admin/container/get_container_detail", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**查询指定虚拟机信息(管理员查询) */
export const getVmAdminContainer = id => {
  return http2.get(`/acs/v1/admin/instance/detail/${id}`);
};
// 暂停容器
export const pauseContainer = data => {
  return http2.post("/acs/v1/admin/container/pause_container", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
// 暂停虚拟机
export const pauseInstance = (data, id) => {
  return http2.post(`/acs/v1/admin/instance/pause/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**恢复虚拟机 */
export const unpauseInstance = (id, data = "") => {
  return http2.post(`/acs/v1/admin/instance/resume/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

// 解除暂停
export const unpauseContainer = data => {
  return http2.post("/acs/v1/admin/container/unpause_container", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取容器状态 */
export const getContainerStatus = data => {
  return http2.post("/acs/v1/admin/container/get_container_status", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取虚拟机状态 */
export const getInstanceStatus = id => {
  return http2.get(`/acs/v1/admin/instance/get_state/${id}`);
};
/**查询服务器状态 */
export const getServerStatus = id => {
  return http2.get(`/acs/v1/admin/server/send_server_status?server_id=${id}`);
};
/**开通容器 */
export const openContainer = data => {
  return http2.post("/acs/v1/admin/container/open_container", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**开通虚拟机 */
export const openInstance = (id, data = "") => {
  return http2.post(`/acs/v1/admin/instance/approve/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**启动容器 */
export const startContainer = data => {
  return http2.post("/acs/v1/admin/container/start_container", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**启动虚拟机 */
export const startInstance = data => {
  return http2.get(`/acs/v1/admin/instance/start/${data}`);
};
/**重装容器 */
export const reinstallC = data => {
  return http2.post("/acs/v1/admin/container/reinstall_container", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**重装虚拟机 */
export const reinstallI = (data, id) => {
  return http2.post(`/acs/v1/admin/instance/reinstall/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**获取容器日志 */
export const getContainerLog = data => {
  return http2.post(`/acs/v1/admin/container/get_container_log`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取虚拟机操作日志 */
export const getInstanceLog = (id, data) => {
  return http2.get(
    `/acs/v1/admin/instance/log/${id}?page=${data.page}&count=${data.count}`
  );
};

/**重启容器 */
export const restartContainer = data => {
  return http2.post("/acs/v1/admin/container/reboot_container", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**重启虚拟机 */
export const restartInstance = data => {
  return http2.get(`/acs/v1/admin/instance/reboot/${data}`);
};

/**停止容器 */
export const stopContainer = data => {
  return http2.post("/acs/v1/admin/container/stop_container", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**停止虚拟机 */
export const stopInstance = data => {
  return http2.get(`/acs/v1/admin/instance/stop/${data}`);
};

/**删除容器 */
export const deleteContainer = data => {
  return http2.post("/acs/v1/admin/container/delete_container", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**删除虚拟机 */
export const deleteInstance = (id, data = "") => {
  return http2.post(`/acs/v1/admin/instance/delete/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**清除容器流量 */
export const clearContainerTraffic = data => {
  return http2.post("/acs/v1/admin/container/clear_container_traffic", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**连接控制台 */
export const connectConsole = data => {
  return http2.post("/acs/v1/admin/container/get_container_console", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**新增虚拟机 （管理员） */
export const addInstance = data => {
  return http2.post("/acs/v1/admin/instance/create_vm", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取虚拟机控制台 */
export const getInstanceConsole = data => {
  return http2.get(`/acs/v1/admin/instance/console/${data}`);
};
/**查询容器所有卷信息 */
export const getVolumeList = data => {
  return http2.get(`/acs/v1/admin/volume/get_volume_list?instance_id=${data.instance_id}&page=${data.page}&count=${data.count}`);
};
/**查询虚拟机所有卷信息 */
export const getInstanceVolumeList = data => {
  return http2.get(
    `/acs/v1/admin/volume/get_volume_list?instance_id=${data.instance_id}&page=${data.page}&count=${data.count}`
  );
};
/**新增卷 */
export const addVolume = data => {
  return http2.post("/acs/v1/admin/volume/add_volume", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**修改卷大小 */
export const updateVolume = data => {
  return http2.post("/acs/v1/admin/volume/update_volume_size", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**删除数据卷 */
export const deleteVolume = data => {
  return http2.post("/acs/v1/admin/volume/delete_volume", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**获取容器网络信息 */
export const getNetworkList = data => {
  return http2.get(
    `/acs/v1/container/proxy/get_container_proxy?container_id=${data}`
  );
};
/**获取虚拟机端口列表 */
export const getInstancePortList = data => {
  const params = new URLSearchParams();
  if (data.page !== undefined) params.append("page", data.page.toString());
  if (data.count !== undefined) params.append("count", data.count.toString());
  if (data.internal_port !== undefined)
    params.append("internal_port", data.internal_port.toString());
  return http2.get(
    `/acs/v1/admin/instance_port/list?instance_id=${data.instance_id}&${params.toString()}`
  );
};
/**添加容器网络 */
export const addNetwork = data => {
  return http2.post("/acs/v1/container/proxy/add_container_proxy", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**创建端口 */
export const addPort = data => {
  return http2.post("/acs/v1/admin/instance_port/create", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取浮动ip列表 */
export const getFloatingIpList = data => {
  return http2.get(
    `/acs/v1/admin/floating_ip/get_list?server_id=${data.server_id}&page=${data.page}&count=${data.count}`
  );
};
/**新增浮动ip */
export const addFloatingIp = data => {
  return http2.post("/acs/v1/admin/floating_ip/add", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**批量添加浮动ip */
export const addFloatingIpBatch = data => {
  return http2.post("/acs/v1/admin/floating_ip/add_list", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**删除浮动ip */
export const delFloatingIp = data => {
  return http2.post("/acs/v1/admin/floating_ip/delete", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**获取单个用户操作日志 */
export const getUserLog = data => {
  return http2.get(
    `/acs/v1/user/procedure/get_user_log?user_id=${data.user_id}&page=${data.page}&count=${data.count}`
  );
};

/**管理员修改头像 */
export const editAvatar = data => {
  return http2.post("/acs/v1/admin/users/upload_user_avatar", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**获取服务器硬盘信息 */
export const getDiskInfo = data => {
  return http2.get(`/acs/v1/admin/server/get_server_disk?server_id=${data}`);
};
/**获取服务器实际划分硬盘信息 */
export const getRealDisk = data => {
  return http2.get(`/acs/v1/admin/server/get_server_disk_info?server_id=${data}`);
};
/**获取服务器流量信息 */
export const getTraffic = data => {
  return http2.get(`/acs/v1/admin/server/get_server_bandwidth?server_id=${data}`);
};
/**获取服务器总流量信息 */
export const getTotalTraffic = data => {
  return http2.get(`/acs/v1/admin/server/get_server_total_bandwidth?server_id=${data}`);
};
/**获取版本更新 */
export const getVersion = () => {
  return http2.get(`/acs/v1/admin/version`);
};

// 管理员删除https网络
export const AdminDelHttps = data => {
  return http2.post("/acs/v1/container/proxy/del_https_connet", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

// 管理员添加https网络
export const AdminAddHttps = data => {
  return http2.post("/acs/v1/container/proxy/add_https_proxy", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取指定端口信息 */
export const getPortInfo = data => {
  return http2.get(`/acs/v1/admin/instance_port/detail?port_id=${data}`);
};
/**新增卷 */
export const addVolumeMount = data => {
  return http2.post("/acs/v1/admin/volume/add_volume", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**进入救援系统 */
export const rescueInstance = id => {
  return http2.get(`/acs/v1/admin/instance/rescue/enter/${id}`);
};

/**退出救援系统 */
export const exitRescueInstance = id => {
  return http2.get(`/acs/v1/admin/instance/rescue/exit/${id}`);
};

/**修改虚拟机密码 */
export const changeInstancePassword = (id, data) => {
  return http2.post(`/acs/v1/admin/instance/update_password/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**修改虚拟机密码(用户) */
export const changeInstancePasswordUser = (id, data) => {
  return http2.post(`/acs/v1/user/instance/update_password/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**删除端口 */
export const deletePort = data => {
  return http2.post("/acs/v1/admin/instance_port/delete", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
