import { defHttp } from '/@/utils/http/axios';
import type {
  ContactPageParams,
  ContactModal,
  ContactParams,
  ContactInfo,
  ConfigPageParams,
} from './model/alarmContactModal';
import { getPageData } from '../../base';
import { DeviceModel, DeviceQueryParam } from '../../device/model/deviceModel';
enum API {
  alarmContact = '/alarm_contact',
  updateAlarmContact = '/alarm/profile',
  devicePage = '/device',
  deleteAlarmConfig = '/alarm/profile',
  getAlarmConfig = '/alarm/profile',
  getAlarmConfigStatus = '/alarm/profile',
  byOrgIdGetAlarmContactApi = '/alarm_contact/',
}

//根据组织id获取对应告警联系人
export const byOrgIdGetAlarmContact = (params) => {
  return defHttp.get({
    url: API.byOrgIdGetAlarmContactApi + params,
  });
};

// 获取
export const getAlarmContact = (params: ContactPageParams) => {
  return getPageData<ContactModal>(params, API.alarmContact);
};

// 新增
export const addAlarmContact = (params: ContactParams) => {
  return defHttp.post({
    url: API.alarmContact,
    data: params,
  });
};

// 更新
export const updateAlarmContact = (params: ContactParams) => {
  return defHttp.post({
    url: API.updateAlarmContact,
    data: params,
  });
};

// 删除
export const deleteAlarmContact = (ids: string[]) => {
  return defHttp.delete({
    url: API.alarmContact,
    data: ids,
  });
};

// 查询设备分页数据
export const devicePage = (params: DeviceQueryParam) => {
  return defHttp.get<DeviceModel>({
    url: API.devicePage,
    params,
  });
};

// 新增或者编辑告警配置
export const saveOrEditAlarmConfig = (params: ContactInfo) => {
  return defHttp.post({
    url: API.updateAlarmContact,
    data: params,
  });
};

/**
 * 删除告警配置
 */
export const deleteAlarmConfig = (ids: string[]) => {
  return defHttp.delete({
    url: API.deleteAlarmConfig,
    data: {
      ids: ids,
    },
  });
};

/**
 * 告警配置分页
 */

export const queryAlarmConfig = (params: ConfigPageParams) => {
  return defHttp.get<ConfigPageParams>({
    url: API.getAlarmConfig,
    params,
  });
};

/**
 * 告警配置状态
 */
export const putAlarmConfigStatus = (status?: number, alarmProfileId?: string) =>
  defHttp.get({
    url: API.getAlarmConfigStatus + '/' + alarmProfileId + '/' + status,
  });
