import { fetchApi } from '@/api/client' export type Household = { id: number; name: string; slug: string } export async function acceptInvitation(token: string): Promise { const resp = await fetchApi('/api/v1/invitations/accept', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token }), }) if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText || 'HTTP error'}`) const data = await resp.json().catch(() => null) const h = data?.household if (!h || typeof h.id !== 'number' || typeof h.slug !== 'string' || typeof h.name !== 'string') { throw new Error('Invalid invitation accept response') } return { id: h.id, name: h.name, slug: h.slug } }