import {
  BE_GESTIONEMAIL_SEARCH_RECIPIENTS_URL,
  BE_GESTIONEMAIL_SEND_EMAIL_URL,
  BE_GESTIONEMAIL_SEND_FEEDBACK_URL,
} from '@/utils/Url';
import { fetchWithAuth } from '@/utils/fetchWithAuth';
import { getCsrfToken } from '@/utils/getCsrfToken';

// Recherche de destinataires pour email
export const searchRecipients = (establishmentId, query) => {
  const url = `${BE_GESTIONEMAIL_SEARCH_RECIPIENTS_URL}/?establishment_id=${establishmentId}&q=${encodeURIComponent(query)}`;
  return fetchWithAuth(url);
};
// Envoyer un email
export const sendEmail = async (messageData) => {
  const csrfToken = getCsrfToken();
  return fetchWithAuth(BE_GESTIONEMAIL_SEND_EMAIL_URL, {
    method: 'POST',
    headers: { 'X-CSRFToken': csrfToken },
    body: JSON.stringify(messageData),
  });
};

// Envoyer un feedback au support
export const sendFeedback = async (feedbackData) => {
  const csrfToken = getCsrfToken();
  return fetchWithAuth(BE_GESTIONEMAIL_SEND_FEEDBACK_URL, {
    method: 'POST',
    headers: { 'X-CSRFToken': csrfToken },
    body: JSON.stringify(feedbackData),
  });
};
