import { API_BASE_URL } from "@config/config_frontend"; export interface RegisterPayload { email: string; password: string; password_confirm: string; name: string; position: string | null; phone: string | null; terms_version: string; terms_agreed: boolean; privacy_agreed: boolean; marketing_agreed: boolean; } async function request(path: string, body: object): Promise> { const response = await fetch(`${API_BASE_URL}${path}`, { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); const result = (await response.json()) as Record; if (!response.ok) throw new Error(String(result.detail ?? "Request failed")); return result; } export function requestRegistration(payload: RegisterPayload): Promise> { return request("/auth/register/request", payload); } export function verifyRegistration( email: string, otpCode: string, ): Promise> { return request("/auth/register/verify", { email, otp_code: otpCode }); } export async function searchCompanies(query: string): Promise<{ id: number; name: string }[]> { const response = await fetch(`${API_BASE_URL}/auth/companies?q=${encodeURIComponent(query)}`); const result = (await response.json()) as { detail?: string; companies?: { id: number; name: string }[]; }; if (!response.ok) throw new Error(result.detail ?? "Request failed"); return result.companies ?? []; }