import { defHttp } from '/@/utils/http/axios';
import type {
  ContactPageParams,
  ContactModal,
  ContactParams,
  ContactInfo,
} from './model/alarmContactModal';
import { getPageData } from '../../base';
import { DeviceModel, DeviceQueryParam } from '../../device/model/deviceModel';
import { omit } from 'lodash-es';
enum API {
  alarmContact = '/alarm_contact',
  updateAlarmContact = '/alarm_contact/update',
  devicePage = '/device',
}

// 获取
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 saveOrEditAlarmContact = (params: ContactInfo, isUpdate: boolean) => {
  if (isUpdate) return updateAlarmContact(params);
  return addAlarmContact(params);
};

// 查询设备分页数据
export const devicePage = (params: DeviceQueryParam) => {
  const { page, pageSize } = params;
  const otherParams = omit(params, ['page', 'pageSize']);
  return defHttp.post<DeviceModel>({
    url: `${API.devicePage}?page=${page}&pageSize=${pageSize}`,
    params: otherParams,
  });
};
