import type { VolunteerPickerRecord } from "@/features/opportunities/rolesAndTeamsRecord";
import apiClient from "@/lib/api/client";
import type { ApiResponse, QueryParams } from "@/lib/api/types";

/**
 * One row of `GET /list-organizations/`.
 *
 * `OrganizationListResource` projects exactly two keys — `id` and `full_name`,
 * the latter being `company_name`, which is `->nullable()`. Three sponsor
 * pickers read a `company_name` fallback off these rows; the resource does not
 * emit that key, so the fallback can never fire.
 *
 * The current endpoint accepts `name`, `for_sponsorship`, `page`, `limit`
 * and `ids` as a comma-separated list (backend `bf3140b`). Use the sponsorship
 * filter on targeted lookups too, so legacy teams/self-sponsors stay excluded.
 */
export interface DirectoryOrganization {
  id: number;
  full_name: string | null;
}

export const getAllOrganizations = (
  params?: QueryParams
): Promise<ApiResponse<DirectoryOrganization[]>> =>
  apiClient.get("/list-organizations/", { params }).then((r) => r.data);

/**
 * The volunteer picker for the attendance / scan-permission tables.
 *
 * `VolunteerPickerResource` deliberately exposes only the last four digits of
 * a civil id, passport or phone — and it emits **no `is_public`**, so a caller
 * cannot choose between the private and public profile routes from this row.
 */
export const getAvailableVolunteers = (
  params?: QueryParams
): Promise<ApiResponse<VolunteerPickerRecord[]>> =>
  apiClient.get("/available-volunteers/", { params }).then((r) => r.data);
