import http from '@/http';

export interface Participant {
  id: number;
  pseudo: string;
  userId: number;
}

export interface ParticipationList {
  count: number;
  participants: Participant[];
}

export interface ParticipationResponse {
  id: number;
  evenementId: number;
  pseudo: string;
}

export interface MyParticipation {
  id: number;
  evenementId: number;
  eventDate: string;
  eventTitle: string;
  eventLocation: string;
}

export async function getMyParticipations(): Promise<MyParticipation[]> {
  const response = await http.get('/participations/me');
  return response.data;
}

export async function getParticipations(evenementId: number): Promise<ParticipationList> {
  const response = await http.get(`/participations?evenementId=${evenementId}`);
  return response.data;
}

export async function registerParticipation(evenementId: number): Promise<ParticipationResponse> {
  const response = await http.post('/participations', { evenementId });
  return response.data;
}

export async function cancelParticipation(id: number): Promise<void> {
  await http.delete(`/participations/${id}`);
}
