import { http } from '@/utils/http/axios';
import type {
  WarningInfoListResponse,
  DefenseNoticeListResponse,
  WarningInfoDetailResponse,
  DefenseNoticeDetailResponse,
  DefenseNoticeListQuery,
  WarningInfoListQuery,
} from '@/types/disaster-warning';
import type { WarningInfoRuleForm, DefenseNoticeRuleForm } from '@/views/disaster/disaster-warning/src/type';
import type { QueryPageRequest, QueryPageResponse } from '@/types/basic-query';
/**
 * 获取预警信息列表
 */
export function getWarningInfoList(query: QueryPageRequest<WarningInfoListQuery>) {
  return http.request<QueryPageResponse<WarningInfoListResponse>>({
    url: '/disasterWarn/queryDisasterWarnInfoPage',
    method: 'post',
    data: query,
  });
}

/**
 * 创建预警信息项
 */
export const createWarningInfoItem = (data: Omit<WarningInfoRuleForm, 'createUser'>) => {
  return http.request({
    url: '/disasterWarn/saveDisasterWarnInfo',
    method: 'post',
    data,
  });
};

/**
 * 查看预警信息详情
 */
export function getWarningInfoDetail(disasterWarnInfoId: number) {
  return http.request<WarningInfoDetailResponse>({
    url: 'disasterWarn/queryDisasterWarnInfo',
    method: 'get',
    params: {
      disasterWarnInfoId,
    },
  });
}

/**
 * 编辑预警信息
 */
export const editWarningInfoItem = (data: Omit<WarningInfoRuleForm, 'createUser'>) => {
  return http.request({
    url: '/disasterWarn/updateDisasterWarnInfo',
    method: 'post',
    data,
  });
};

/**
 *  发布、撤消防御通知
 */
export const publishWarningInfoItem = (editParam: { id: number; effectState: number }) => {
  return http.request({
    url: '/disasterWarn/updateWarnEffectState',
    method: 'post',
    data: editParam,
  });
};

/**
 * 删除预警信息
 */
export const deleteWarningInfoItem = (disasterWarnInfoIds: number) => {
  return http.request({
    url: '/disasterWarn/deleteDisasterWarnInfos?disasterWarnInfoIds=' + disasterWarnInfoIds,
    method: 'post',
  });
};

/**
 * 获取防御通知列表
 */
export function getDefenseNoticeList(query: QueryPageRequest<DefenseNoticeListQuery>) {
  return http.request<QueryPageResponse<DefenseNoticeListResponse>>({
    url: '/defenseNotice/queryDefenseNoticeInfoPage',
    method: 'post',
    data: query,
  });
}

/**
 * 创建防御通知项
 */
export const createDefenseNoticeItem = (data: Omit<DefenseNoticeRuleForm, 'createUser'>) => {
  return http.request({
    url: '/defenseNotice/saveDefenseNoticeInfo',
    method: 'post',
    data,
  });
};

/**
 * 编辑防御通知项
 */
export const editDefenseNoticeItem = (data: Omit<DefenseNoticeRuleForm, 'createUser'>) => {
  return http.request({
    url: '/defenseNotice/updateDefenseNoticeInfo',
    method: 'post',
    data,
  });
};

/**
 * 查看防御通知详情
 */
export const getDefenseNoticeDetail = (id: number) => {
  return http.request<DefenseNoticeDetailResponse>({
    url: '/defenseNotice/queryDefenseNoticeInfo',
    method: 'get',
    params: {
      id,
    },
  });
};

/**
 *  发布、撤消防御通知
 */
export const publishDefenseNoticeItem = (editParam: { id: number; effectState: number }) => {
  return http.request({
    url: '/defenseNotice/updateNoticeEffectState',
    method: 'post',
    data: editParam,
  });
};

/**
 * 删除防御通知项
 */
export const deleteDefenseNoticeItem = (defenseNoticeInfoIds: number) => {
  return http.request({
    url: '/defenseNotice/deleteDefenseNoticeInfos?defenseNoticeInfoIds=' + defenseNoticeInfoIds,
    method: 'post',
  });
};
