import { apiClient } from './client';
import type { EventoFiscal, EventoCreate, EventoUpdate } from '@horux/shared';

export async function getEventos(año: number, contribuyenteId?: string | null): Promise<EventoFiscal[]> {
  const params = new URLSearchParams({ año: año.toString() });
  if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
  const response = await apiClient.get<EventoFiscal[]>(`/calendario/generados?${params}`);
  return response.data;
}

export async function getProximos(dias = 30): Promise<EventoFiscal[]> {
  const response = await apiClient.get<EventoFiscal[]>(`/calendario/proximos?dias=${dias}`);
  return response.data;
}

export async function createEvento(data: EventoCreate): Promise<EventoFiscal> {
  const response = await apiClient.post<EventoFiscal>('/calendario', data);
  return response.data;
}

export async function updateEvento(id: number, data: EventoUpdate): Promise<EventoFiscal> {
  const response = await apiClient.patch<EventoFiscal>(`/calendario/${id}`, data);
  return response.data;
}

export async function deleteEvento(id: number): Promise<void> {
  await apiClient.delete(`/calendario/${id}`);
}
