import { request } from "@/api/request";

/** 获取告警级别列表（分页） */
export const fetchAlertLevelList = (data?: {
  page?: number;
  page_size?: number;
  keyword?: string;
  enabled?: string;
}) => {
  return request.get("/Alert/v1/severity/list", { params: data || {} });
};

/** 获取告警级别下拉选项（不分页），默认仅返回 enabled=true */
export const fetchAlertLevelOptions = (data?: {
  keyword?: string;
  enabled?: 'true' | 'false';
}) => {
  return request.get("/Alert/v1/severity/options", {
    params: {
      keyword: data?.keyword || undefined,
      enabled: data?.enabled ?? 'true',
    },
  })
}

/** 获取告警级别详情 */
export const fetchAlertLevelDetail = (id: number) => {
  return request.get(`/Alert/v1/severity/get/${id}`);
};

/** 创建告警级别 */
export const createAlertLevel = (data: {
  name: string;
  code: string;
  description?: string;
  color: string;
  icon?: string;
  priority?: number;
  enabled?: boolean;
  config?: string;
}) => {
  return request.post("/Alert/v1/severity/create", data);
};

/** 更新告警级别 */
export const updateAlertLevel = (data: {
  id: number;
  name?: string;
  code?: string;
  description?: string;
  color?: string;
  icon?: string;
  priority?: number;
  enabled?: boolean;
  config?: string;
}) => {
  return request.post("/Alert/v1/severity/update", data);
};

/** 删除告警级别 */
export const deleteAlertLevel = (id: number) => {
  return request.delete(`/Alert/v1/severity/delete/${id}`);
};
