/**
 * Comment Service
 * Handles CRUD operations for event comments
 */

import http from '@/http';
import { Comment } from '@/types/comment';

/**
 * Get comments for a specific event
 */
export async function getCommentsByEvenement(evenementId: number): Promise<Comment[]> {
  const response = await http.get(`/commentaires-evenement?evenementId=${evenementId}`);
  return response.data;
}

/**
 * Create a comment on an event
 */
export async function createComment(evenementId: number, texte: string): Promise<Comment> {
  if (!texte || texte.trim() === '') {
    throw new Error('Comment text is required');
  }

  const response = await http.post('/commentaires-evenement', {
    evenementId,
    texte,
  });
  return response.data;
}

/**
 * Delete a comment
 */
/** L'auteur corrige le texte de son commentaire. */
export async function updateComment(commentId: number, texte: string): Promise<Comment> {
  const response = await http.patch(`/commentaires-evenement/${commentId}`, {texte});
  return response.data;
}

export async function deleteComment(commentId: number): Promise<void> {
  await http.delete(`/commentaires-evenement/${commentId}`);
}
