import { defHttp } from '@jdlinker/func';

export const getProviders = () => defHttp.get({ url: `/gateway/device/providers` }, { isTransformResponse: false });

export const detail = (id: any) => defHttp.get({ url: `/gateway/device/${id}` }, { isTransformResponse: false });

export const getNetworkList = (networkType: string, include: string, data: Object) =>
  defHttp.get({ url: `/network/config/${networkType}/_alive?include=${include}`, data }, { isTransformResponse: false });

export const getProtocolList = (transport: string, params: Object) =>
  defHttp.get({ url: `/protocol/supports/${transport ? transport : ''}`, params }, { isTransformResponse: false });

export const getConfigView = (id: string, transport: string) =>
  defHttp.get({ url: `/protocol/${id}/transport/${transport}` }, { isTransformResponse: false });

export const getChildConfigView = (id: string) =>
  defHttp.get({ url: `/protocol/${id}/transports` }, { isTransformResponse: false });

export const save = (data: Object) => defHttp.post({ url: `/gateway/device`, data }, { isTransformResponse: false });

export const update = (data: Object) => defHttp.put({ url: `/gateway/device`, data }, { isTransformResponse: false });

export const list = (data: any) => {
  const params = { ...data };
  return defHttp.post({ url: `/gateway/device/list`, data, params }, { isTransformResponse: false });
};

export const undeploy = (id: string) =>
  defHttp.post({ url: `/gateway/device/${id}/_shutdown` }, { isTransformResponse: false });

export const deploy = (id: string) =>
  defHttp.post({ url: `/gateway/device/${id}/_startup` }, { isTransformResponse: false });

export const remove = (id: string) => defHttp.delete({ url: `/gateway/device/${id}` }, { isTransformResponse: false });

export const getResourcesCurrent = () =>
  defHttp.get({ url: `/network/resources/alive/_current` }, { isTransformResponse: false });

export const getClusters = () => defHttp.get({ url: `/network/resources/clusters` }, { isTransformResponse: false });

export const getPluginList = (data: any) =>
  defHttp.post({ url: '/plugin/driver/_query/no-paging', data }, { isTransformResponse: false });

export const getPluginConfig = (id: string) =>
  defHttp.get({ url: `/plugin/driver/${id}/description` }, { isTransformResponse: false });

export const getCommandsByAccess = (id: string) =>
  defHttp.get({ url: `/gateway/device/${id}/commands` }, { isTransformResponse: false });

export const getCommandsDevicesByAccessId = (id: string, data: any) =>
  defHttp.post({ url: `/gateway/device/${id}/command/QueryDevicePage`, data });
