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

// 获取图像验证码
export const Captch = data => {
  return http2.get(`/acs/v1/user/check/get_code_img`);
};

/** 登录 */
export const getLogin = data => {
  return http2.post("/acs/v1/user/login", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

// // /** 刷新token */
// export const refreshTokenApi = (data?: object) => {
//   return http.request<RefreshTokenResult>("post", "/refresh-token", { data });
// };

/**获取用户列表 */
export const getUserList = data => {
  return http2.get(
    `/acs/v1/admin/users/get_user_list?page=${data.page}&count=${data.count}&key=${data.key}`
  );
};
/**添加用户 */
export const addUser = data => {
  return http2.post("/acs/v1/admin/users/add_user", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**编辑用户信息 */
export const editUser = data => {
  return http2.post("/acs/v1/admin/users/update_user", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**修改用户密码 */
export const editPassword = data => {
  return http2.post("/acs/v1/admin/users/update_user_password", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**删除用户 */
export const deleteUser = data => {
  return http2.post("/acs/v1/admin/users/del_user", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**查询单个用户 */
export const userDetail = data => {
  return http2.post("/acs/v1/admin/users/select_user", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**修改用户余额 */
export const editBalance = data => {
  return http2.post("/acs/v1/admin/users/update_user_balance", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取用户服务器 */
export const getUserServer = (data = {}) => {
  const serverType = data.server_type || "dockerContainer"; // 设置默认值
  return http2.get(
    `/acs/v1/user/procedure/get_server_list?server_type=${serverType}`
  );
};
/**用户获取虚拟机列表 */
export const getVirtualList = data => {
  let url = `/acs/v1/user/instance/list?page=${data.page}&count=${data.count}`;
  if (data.key) {
    url += `&key=${data.key}`;
  }
  if (data.server_id) {
    url += `&server_id=${data.server_id}`;
  }
  return http2.get(url);
};
/**用户获取服务器套餐 */
export const getUserPackage = data => {
  return http2.get(`/acs/v1/user/procedure/get_server_plan_list?server_id=${data}`);
};
/**获取用户容器列表 */
export const getUserContainer = data => {
  return http2.get(
    `/acs/v1/user/container/list?page=${data.page}&count=${data.count}`
  );
};
/**用户按地区获取容器 */
export const getUserContainerD = data => {
  return http2.get(
    `/acs/v1/user/container/list?page=${data.page}&count=${data.count}&server_id=${data.server_id}`
  );
};
/**获取用户操作日志 */
export const get_user_log = () => {
  return http2.get(`/acs/v1/user/procedure/get_user_log`);
};
/**获取用户自身信息 */
export const getUserInfo = () => {
  return http2.get(`/acs/v1/user/procedure/get_user_info`);
};
/**获取用户自身信息 */
export const getUserInfoV1 = () => {
  return http2.get(`/acs/v1/user/info/get_user_info`);
};
/**用户实名 */
export const realName = data => {
  return http2.post("/acs/v1/external/real_name", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**发送手机验证码 */
export const sendCode = data => {
  return http2.post("/acs/v1/external/send_message", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**发送邮箱验证码 */
export const sendEmailCode = data => {
  return http2.post("/acs/v1/external/send_email", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**用户注册 */
export const register = data => {
  return http2.post("/acs/v1/user/register", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**手机号修改校证码 */
export const CodePhone = data => {
  return http2.post("/acs/v1/user/info/ask_update_user_phone", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**修改手机号码 */
export const SetPhone = data => {
  return http2.post("/acs/v1/user/info/update_user_phone", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**邮箱修改校证码 */
export const CodeEmail = data => {
  return http2.post("/acs/v1/user/info/ask_update_user_email", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**修改邮箱 */
export const SetEmail = data => {
  return http2.post("/acs/v1/user/info/update_user_email", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**上传头像 */
export const uploadAvatar = data => {
  return http2.post("/acs/v1/user/info/upload_user_avatar", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**手机号忘记密码 */
export const forgetphone = data => {
  return http2.post("/acs/v1/user/info/forget_user_password_phone", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**邮箱忘记密码 */
export const forgetemail = data => {
  return http2.post("/acs/v1/user/info/forget_user_password_email", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**管理员全局搜索 */
export const Find = data => {
  return http2.post("/acs/v1/admin/search", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
// 管理员删除容器网络
export const delContainer = data => {
  return http2.post("/acs/v1/user/container/delete_connect", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
// 删除端口
export const delPort = data => {
  return http2.post("/acs/v1/admin/instance_port/delete", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
// 自定义容器价格
export const Containerpay = data => {
  return http2.post("/acs/v1/admin/container/update_container_price", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
// 修改虚拟机续费价格
export const Containerpaytime = (data, id) => {
  return http2.post(`/acs/v1/admin/instance/update_price/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
// 自定义容器到期时间
export const Containertime = data => {
  return http2.post("/acs/v1/admin/container/update_container_expire_time", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
// 修改虚拟机续到期时间
export const Containertimetime = (data, id) => {
  return http2.post(`/acs/v1/admin/instance/update_expire_time/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
// 修改虚拟机信息
export const editContainer = (data, id) => {
  return http2.post(`/acs/v1/admin/instance/update/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/***************************************容器管理 ************************/

/** 容器操作 */
export const startUserContainer = (type, id) => {
  return http2.post(
    "/acs/v1/user/container/" + type,
    {
      container_id: id
    },
    {
      headers: {
        "Content-Type": "multipart/form-data"
      }
    }
  );
};
/**用户容器退款 */
export const backUserContainer = data => {
  return http2.post("/acs/v1/user/container/delete", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**重装容器 */
export const reinContainer = data => {
  return http2.post("/acs/v1/user/container/reinstall", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**重装虚拟机 */
export const reinVmContainer = (id, data) => {
  return http2.post(`/acs/v1/user/instance/reinstall/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/** 容器操作 */
export const startAdminContainer = (type, id) => {
  return http2.post(
    "/acs/v1/admin/container/" + type,
    {
      container_id: id
    },
    {
      headers: {
        "Content-Type": "multipart/form-data"
      }
    }
  );
};
/** 容器操作 */
export const procedureUpdateContainerRenew = data => {
  return http2.post("/acs/v1/user/procedure/update_container_renew", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取容器完整信息 */
export const getContainerDetail = id => {
  return http2.get(`/acs/v1/user/container/detail?container_id=${id}`);
};
/**获取虚拟机完整信息 */
export const getVmContainerDetail = id => {
  return http2.get(`/acs/v1/user/instance/detail/${id}`);
};
/**容器操作信息 */
export const containerLog = data => {
  return http2.post("/acs/v1/user/container/logs", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**虚拟机操作日志 */
export const vmLog = data => {
  return http2.get(
    `/acs/v1/user/instance/log/${data.id}?page=${data.page}&count=${data.count}`
  );
};
/**获取容器状态 */
export const getContainerStatus = data => {
  return http2.post(`/acs/v1/user/container/status`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取虚拟机状态 */
export const getVmStatus = id => {
  return http2.get(`/acs/v1/user/instance/get_state/${id}`);
};
/**获取容器运行日志 */
export const getContainerLog = data => {
  return http2.post(`/acs/v1/user/container/run_logs`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取容器购买网络订单 */
export const getContainerList = data => {
  return http2.post(`/acs/v1/user/procedure/add_network`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**计算容器网络价格 */
export const getContainerPrice = data => {
  return http2.post(`/acs/v1/user/procedure/get_price_network`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/** 启动虚拟机 */
export const start_vm = id => {
  return http2.get(`/acs/v1/user/instance/start/${id}`);
};
/** 停止虚拟机（关机） */
export const stop_vm = id => {
  return http2.get(`/acs/v1/user/instance/stop/${id}`);
};
/**重启虚拟机 */
export const restart_vm = id => {
  return http2.get(`/acs/v1/user/instance/reboot/${id}`);
};
/**获取虚拟机控制台 */
export const get_vm_console = id => {
  return http2.get(`/acs/v1/user/instance/console/${id}`);
};
/**进入救援系统 */
export const rescue_vm = id => {
  return http2.get(`/acs/v1/user/instance/rescue/enter/${id}`);
};
/**退出救援系统 */
export const unrescue_vm = id => {
  return http2.get(`/acs/v1/user/instance/rescue/exit/${id}`);
};

// *******************************  new
/** 提交充值订单 */
export const user_update_container_recharge = data => {
  return http2.post("/acs/v1/user/procedure/update_container_recharge", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/** 提交容器订单 */
export const user_update_plan_info = data => {
  return http2.post("/acs/v1/user/procedure/update_plan_info", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/** 提交虚拟机订单 */
export const user_update_vm_info = data => {
  return http2.post("/acs/v1/user/procedure/create_vm_trade", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取订单简略信息 */
export const getOrderDetail = id => {
  return http2.get(`/acs/v1/user/procedure/get_low_trade_info?trade_id=${id}`);
};
/**支付请求 */
export const pay_request = data => {
  return http2.post("/acs/v1/external/pay", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**用户删除容器网络 */
export const deleteConNet = data => {
  return http2.post("/acs/v1/user/container/delete_connect", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

// 添加https
export const additionHttp = data => {
  return http2.post("/acs/v1/user/container/add_https_connet", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

// 删除https
export const DelHttp = data => {
  return http2.post("/acs/v1/user/container/del_https_connet", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取新增虚拟机端口价格 */
export const getVmPortPrice = data => {
  return http2.post("/acs/v1/user/procedure/get_price_instance_port", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**提交新增虚拟机端口订单 */
export const addVmPort = data => {
  return http2.post("/acs/v1/user/procedure/add_instance_port", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
