import { http } from "@/utils/http";

type Result = {
  code: number;
  message: string;
  data?: any;
};

type ResultTable = {
  code: number;
  message: string;
  data?: {
    list: Array<any>;
    total: number;
    pageSize: number;
    currentPage: number;
  };
};

export const getAnnouncementList = (params: {
  page?: number;
  pageSize?: number;
  title?: string;
  type?: number;
  status?: number;
}) => {
  return http.request<ResultTable>("get", "/announcement/list", { params });
};

export const getAnnouncementById = (id: number) => {
  return http.request<Result>("get", `/announcement/${id}`);
};

export const createAnnouncement = (data: any) => {
  return http.request<Result>("post", "/announcement", { data });
};

export const updateAnnouncement = (id: number, data: any) => {
  return http.request<Result>("put", `/announcement/${id}`, { data });
};

export const deleteAnnouncement = (id: number) => {
  return http.request<Result>("delete", `/announcement/${id}`);
};

export const publishAnnouncement = (id: number) => {
  return http.request<Result>("put", `/announcement/${id}/publish`);
};

export const offlineAnnouncement = (id: number) => {
  return http.request<Result>("put", `/announcement/${id}/offline`);
};

export const setAnnouncementTop = (id: number, isTop: number) => {
  return http.request<Result>(
    "put",
    `/announcement/${id}/top?isTop=${isTop}`
  );
};
