import { http } from "@/utils/http";
import { interfaceUrlApi } from "../utils";

export interface BasicResponseModel<T = any> {
  code: number;
  msg: string;
  list: T;
  data: T;
  total: number;
}

/**
 * 获取接口列表
 * @param query
 */
export const getIpInterfaceList = (query?: object) => {
  return http.get<BasicResponseModel, any>(
    interfaceUrlApi("ipInterface/list"),
    {
      params: query
    }
  );
};

/**
 * 新增或编辑接口
 * @param data
 */
export const addOrEditIpInterface = (data?: object) => {
  return http.post<BasicResponseModel, any>(
    interfaceUrlApi("ipInterface/saveOrUpdate"),
    {
      data
    }
  );
};

/**
 * 删除接口
 * @param id
 */
export const deleteIpInterface = (id: number) => {
  return http.request<BasicResponseModel>(
    "delete",
    interfaceUrlApi(`ipInterface/delete/${id}`)
  );
};

/**
 * 删除与账户关联的接口
 * @param id
 */
export const delAccountInterface = (id: number) => {
  return http.request<BasicResponseModel>(
    "delete",
    interfaceUrlApi(`ipInterface/delAccountInterface/${id}`)
  );
};

/**
 * 查询账号下关联的接口列表
 * @param query
 */
export const getIpAccountInterfaceList = (query?: object) => {
  return http.post<BasicResponseModel, any>(
    interfaceUrlApi("ipInterface/account/ref/list"),
    {
      data: query
    }
  );
};

/**
 * 接口下拉列表
 * @param query
 */
export const getIpInterfaceOptionList = (query?: object) => {
  return http.post<BasicResponseModel, any>(
    interfaceUrlApi("ipInterface/optionList"),
    {
      params: query
    }
  );
};

/**
 * 保存账号关联的接口
 * @param data
 */
export const addOrEditIpAccountInterfaceRef = (data?: object) => {
  return http.post<BasicResponseModel, any>(
    interfaceUrlApi("ipInterface/interfaceConfig"),
    {
      data
    }
  );
};

/**
 * 切换接口状态
 * @param data
 */
export const switchIpInterfaceStatus = (data?: object) => {
  return http.post<BasicResponseModel, any>(
    interfaceUrlApi(`ipInterface/switchStatus`),
    {
      data
    }
  );
};

/**
 * 切换账号关联的接口状态
 * @param data
 */
export const switchIpAccountInterfaceStatus = (data?: object) => {
  return http.post<BasicResponseModel, any>(
    interfaceUrlApi(`ipInterface/account/interface/ref/switchStatus`),
    {
      data
    }
  );
};

/**
 * 生成token
 */
export const generateIpAccountToken = () => {
  return http.request<BasicResponseModel>(
    "post",
    interfaceUrlApi(`ipInterface/token/generate`)
  );
};
