import { useQuery } from "@tanstack/react-query";

import useAuth from "@/hooks/useAuth";
import { api } from "@/services/api";

/** Onboarding document setting code for the company's nationality. */
export function documentSettingCode(
  nationality: string | null | undefined,
): string {
  return nationality === "foreign"
    ? "company_onboarding_documents_foreign"
    : "company_onboarding_documents_ethiopian";
}

/**
 * Fetches the FileUploadSetting that describes the documents a booking requires
 * (TIN, license, national ID, passport, …) — the same setting the new-booking
 * document step uses, resolved from the company's nationality.
 *
 * Shared by the resubmit modal and the changes-requested detail view so both
 * render an identical document section.
 */
export function useBookingDocumentSetting() {
  const auth = useAuth();
  const nationality = auth.company?.company?.nationality as
    | string
    | null
    | undefined;

  return useQuery(
    api.fileUploadSettings.getByCode.queryOptions({
      input: { code: documentSettingCode(nationality) },
    }),
  );
}
