import apiClient from "@/lib/api/client";
import type { ApiResponse } from "@/lib/api/types";
import type { ChoiceItem } from "@/lib/choices";
import { reviewedChoices } from "../reviewChoices";

/**
 * One choice table, by `choice_types.name`.
 *
 * `BaseController::choices()` projects exactly `{ id, value_en, value_ar,
 * slug }` — see `ChoiceItem`. Two behaviours worth knowing:
 *
 * - an **unknown or empty** choice type answers with a 404 *error* envelope,
 *   not an empty list, so every reader has to tolerate a missing `data`;
 * - `org_type` is special-cased: it **excludes "Volunteer Team"** (an internal
 *   type that powers the Join Us shortcut and is not one of the six approved
 *   signup choices, BE-51) and is returned in a fixed business order rather
 *   than by id.
 */
export const getDropdownChoices = (
  type: string
): Promise<ApiResponse<ChoiceItem[]>> =>
  apiClient.get(`/choices/${type}/`).then((r) => ({ ...r.data, data: reviewedChoices(type, r.data?.data ?? []) }));

export interface BankOption {
  id: number;
  name_en: string;
  name_ar: string;
}

/** Active banks maintained by the backend dashboard. */
export const getBanks = (): Promise<ApiResponse<BankOption[]>> =>
  apiClient.get("/banks/").then((response) => response.data);
