import { useMutation } from "@tanstack/react-query";
import { apiRequest } from "../lib/api-client";

type GenerateInviteCodeResponse = {
  code: string;
  expiresAt: string;
};

type JoinWithCodeResponse = {
  householdId: string;
  householdName: string;
};

export function useGenerateInviteCode() {
  return useMutation({
    mutationFn: () =>
      apiRequest<GenerateInviteCodeResponse>("/api/households/invite/generate", {
        method: "POST",
      }),
  });
}

export function useJoinWithCode() {
  return useMutation({
    mutationFn: (code: string) =>
      apiRequest<JoinWithCodeResponse>("/api/households/invite/join", {
        method: "POST",
        body: JSON.stringify({ code }),
      }),
  });
}
