// 模拟静态数据
const mockNotices = [
  { noticeId: 1, noticeTitle: '系统公告', noticeType: '1', status: '0', createTime: '2023-01-01' },
  { noticeId: 2, noticeTitle: '维护通知', noticeType: '2', status: '0', createTime: '2023-01-02' }
];

// 查询公告列表
export function listNotice(query) {
  const { pageNum, pageSize, noticeTitle, noticeType, status } = query;
  let filteredNotices = [...mockNotices];
  
  if (noticeTitle) {
    filteredNotices = filteredNotices.filter(notice => notice.noticeTitle.includes(noticeTitle));
  }
  if (noticeType) {
    filteredNotices = filteredNotices.filter(notice => notice.noticeType === noticeType);
  }
  if (status) {
    filteredNotices = filteredNotices.filter(notice => notice.status === status);
  }
  
  const total = filteredNotices.length;
  const start = (pageNum - 1) * pageSize;
  const end = start + pageSize;
  const list = filteredNotices.slice(start, end);
  
  return Promise.resolve({
    total,
    rows: list
  });
}

// 查询公告详细
export function getNotice(noticeId) {
  const notice = mockNotices.find(n => n.noticeId === parseInt(noticeId));
  return Promise.resolve(notice || {});
}

// 新增公告
export function addNotice(data) {
  const newNotice = {
    noticeId: mockNotices.length + 1,
    ...data,
    createTime: new Date().toISOString().split('T')[0]
  };
  mockNotices.push(newNotice);
  return Promise.resolve({ code: 200, msg: '新增成功' });
}

// 修改公告
export function updateNotice(data) {
  const index = mockNotices.findIndex(n => n.noticeId === data.noticeId);
  if (index !== -1) {
    mockNotices[index] = { ...mockNotices[index], ...data };
  }
  return Promise.resolve({ code: 200, msg: '修改成功' });
}

// 删除公告
export function delNotice(noticeId) {
  const index = mockNotices.findIndex(n => n.noticeId === parseInt(noticeId));
  if (index !== -1) {
    mockNotices.splice(index, 1);
  }
  return Promise.resolve({ code: 200, msg: '删除成功' });
}