import type { BoardAccessMode } from '~/types';

const FUNCTION_BASE = 'https://countboards-edvvp3hbnq-du.a.run.app';

export async function fetchCountsFromFunction(
  collection: string,
  access: BoardAccessMode = 'public'
): Promise<number> {
  return await $fetch<{ count: number }>(`${FUNCTION_BASE}`, {
    method: 'POST', // ✅ explicitly typed string
    body: { collection, access }, // ✅ valid JSON object
    credentials: access !== 'public' ? 'include' : undefined, // ✅ conditional credentials
  }).then((res) => res.count || 0);
}
