import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PlanForm, PlanVO, FetchPlanResponse } from './types';

// 获取预案列表
export const fetchReports = (params: PlanForm): AxiosPromise<FetchPlanResponse> => {
  return request({
    url: '/api/emergency_plan/plan/list',
    method: 'get',
    params: {
      page: params.pageNum, // 分页参数中的页码
      page_size: params.pageSize, // 分页参数中的每页大小
      plan_type: params.planType, // 预案类型（可选）
      publish_date: params.publish_date, // 发布日期范围（可选）
      plan_name: params.planName // 预案名称（可选）
    }
  });
};

// 新增预案
export const addReport = (data: PlanVO): AxiosPromise<void> => {
  return request({
    url: '/api/emergency_plan/plan/create',
    method: 'post',
    data: data
  });
};

// 修改预案
export const updateReport = (data: PlanVO): AxiosPromise<void> => {
  return request({
    url: `/api/reports/update/${data.reportNumber}`,
    method: 'put',
    data: data
  });
};

// 删除预案
export const deleteReport = (reportNumber: string): AxiosPromise<void> => {
  return request({
    url: `/api/reports/delete/${reportNumber}`,
    method: 'delete'
  });
};
