/**
 * KRA - Announcement Service
 * Announcement plugin APIs
 */
import request from '@/utils/request';

export interface Announcement {
  ID?: number;
  CreatedAt?: string;
  UpdatedAt?: string;
  title?: string;
  content?: string;
  type?: number;
  status?: number;
}

// Get announcement list
export async function getAnnouncementList(params: {
  page: number;
  pageSize: number;
  title?: string;
  type?: number;
  status?: number;
}) {
  return request.get('/announcement/getAnnouncementList', { params });
}

// Get announcement by ID
export async function getAnnouncementById(params: { ID: number }) {
  return request.get('/announcement/getAnnouncementById', { params });
}

// Create announcement
export async function createAnnouncement(data: Partial<Announcement>) {
  return request.post('/announcement/createAnnouncement', data);
}

// Update announcement
export async function updateAnnouncement(data: Announcement) {
  return request.put('/announcement/updateAnnouncement', data);
}

// Delete announcement
export async function deleteAnnouncement(data: { ID: number }) {
  return request.delete('/announcement/deleteAnnouncement', { data });
}

// Batch delete announcements
export async function deleteAnnouncementByIds(data: { ids: number[] }) {
  return request.delete('/announcement/deleteAnnouncementByIds', { data });
}

// Publish announcement
export async function publishAnnouncement(data: { ID: number }) {
  return request.post('/announcement/publishAnnouncement', data);
}

// Withdraw announcement
export async function withdrawAnnouncement(data: { ID: number }) {
  return request.post('/announcement/withdrawAnnouncement', data);
}

// Get active announcements (for display)
export async function getActiveAnnouncements() {
  return request.get('/announcement/getActiveAnnouncements');
}

// ============ Info APIs (for announcement plugin) ============

// Get info list
export async function getInfoList(params: {
  page: number;
  pageSize: number;
  startCreatedAt?: string;
  endCreatedAt?: string;
}) {
  return request.get('/info/getInfoList', { params });
}

// Get info data source
export async function getInfoDataSource() {
  return request.get('/info/getInfoDataSource');
}

// Create info
export async function createInfo(data: any) {
  return request.post('/info/createInfo', data);
}

// Update info
export async function updateInfo(data: any) {
  return request.put('/info/updateInfo', data);
}

// Delete info
export async function deleteInfo(params: { ID: number }) {
  return request.delete('/info/deleteInfo', { params });
}

// Delete info by IDs
export async function deleteInfoByIds(params: { IDs: number[] }) {
  return request.delete('/info/deleteInfoByIds', { params });
}

// Find info by ID
export async function findInfo(params: { ID: number }) {
  return request.get('/info/findInfo', { params });
}
