import { apiClient } from '@/shared/api/client'
import type { ApiResponse } from '@/shared/types/types'

export interface Announcement {
  id: number
  title: string
  content: string
  category: string
  priority: number
  is_pinned: boolean
  is_important: boolean
  view_count: number
  status: string
  published_at: string | null
  created_at: string
  updated_at: string
}

export interface AnnouncementListParams {
  category?: string
  page?: number
  page_size?: number
}

export interface PaginatedResult<T> {
  items: T[]
  total: number
  page: number
  page_size: number
}

export async function fetchAnnouncements(
  params: AnnouncementListParams = {}
): Promise<PaginatedResult<Announcement>> {
  const { data } = await apiClient.get<ApiResponse<PaginatedResult<Announcement>>>(
    '/announcements',
    { params }
  )
  return data.data
}

export async function fetchAnnouncementDetail(id: number): Promise<Announcement> {
  const { data } = await apiClient.get<ApiResponse<Announcement>>(`/announcements/${id}`)
  return data.data
}
