import { queryOptions } from '@tanstack/react-query';
import { getAnnouncementById, getAnnouncements } from './service';
import type { Announcement, AnnouncementFilters } from './types';

export type { Announcement };

export const announcementKeys = {
  all: ['announcements'] as const,
  list: (filters: AnnouncementFilters) => [...announcementKeys.all, 'list', filters] as const,
  detail: (id: number) => [...announcementKeys.all, 'detail', id] as const
};

export const announcementsQueryOptions = (filters: AnnouncementFilters) =>
  queryOptions({
    queryKey: announcementKeys.list(filters),
    queryFn: () => getAnnouncements(filters)
  });

export const announcementByIdOptions = (id: number) =>
  queryOptions({
    queryKey: announcementKeys.detail(id),
    queryFn: () => getAnnouncementById(id)
  });
