import { apiClient } from '@/lib/api-client';
import type { OrganizerFilters, OrganizerMutationPayload, OrganizersResponse } from './types';

function createQueryString(filters: OrganizerFilters) {
  const params = new URLSearchParams();

  if (filters.status) {
    params.set('status', filters.status);
  }

  return params.toString();
}

export async function getOrganizers(filters: OrganizerFilters = {}) {
  const queryString = createQueryString(filters);
  return apiClient<OrganizersResponse>(`/organizations${queryString ? `?${queryString}` : ''}`);
}

export async function createOrganizer(data: OrganizerMutationPayload) {
  return apiClient<{ success: boolean; organizationId: string }>('/organizations', {
    method: 'POST',
    body: JSON.stringify(data)
  });
}

export async function updateOrganizer(id: string, data: OrganizerMutationPayload) {
  return apiClient<{ success: boolean; message: string }>(`/organizations/${id}`, {
    method: 'PATCH',
    body: JSON.stringify(data)
  });
}

export async function softDeleteOrganizer(id: string) {
  return apiClient<{ success: boolean; message: string }>(`/organizations/${id}`, {
    method: 'DELETE'
  });
}
