import { apiClient } from './api-client';
import type { z } from 'zod/v4';
import type { HouseholdResponseSchema, UpdateHouseholdInput } from '@meshitrack/shared';

type HouseholdResponse = z.infer<typeof HouseholdResponseSchema>;

export async function createHousehold(name: string): Promise<HouseholdResponse> {
  return apiClient.post<HouseholdResponse>('/households', { name });
}

export async function getHousehold(id: string): Promise<HouseholdResponse> {
  return apiClient.get<HouseholdResponse>(`/households/${id}`);
}

export async function updateHousehold(
  id: string,
  data: UpdateHouseholdInput,
): Promise<HouseholdResponse> {
  return apiClient.patch<HouseholdResponse>(`/households/${id}`, data);
}

export async function generateInviteCode(id: string): Promise<HouseholdResponse> {
  return apiClient.post<HouseholdResponse>(`/households/${id}/invite`);
}

export async function joinHousehold(inviteCode: string): Promise<HouseholdResponse> {
  return apiClient.post<HouseholdResponse>('/households/join', { inviteCode });
}
