import apiClient from './client'
import type { 
  ReportData, 
  AggregatedReport, 
  SubmitReportRequest,
  PaginatedResponse,
  PaginationParams 
} from '@/types'

export const reportsApi = {
  async getAll(params?: PaginationParams): Promise<PaginatedResponse<ReportData>> {
    const response = await apiClient.get<PaginatedResponse<ReportData>>('/reports', { params })
    return response.data
  },

  async submit(data: SubmitReportRequest): Promise<ReportData> {
    const response = await apiClient.post<ReportData>('/reports', data)
    return response.data
  },

  async update(id: number, data: SubmitReportRequest): Promise<ReportData> {
    const response = await apiClient.put<ReportData>(`/reports/${id}`, data)
    return response.data
  },

  async getAggregated(): Promise<AggregatedReport> {
    const response = await apiClient.get<AggregatedReport>('/reports/aggregated')
    return response.data
  },

  async getAggregatedByUnit(unitId: number): Promise<AggregatedReport> {
    const response = await apiClient.get<AggregatedReport>(`/reports/aggregated/${unitId}`)
    return response.data
  }
}
