import { z } from "zod";

// Shared between apps/api (server-side validation) and apps/web (client-side
// validation for instant feedback) — see schemas/auth.ts for the full
// rationale, same pattern here.

/** Payload accepted by `PATCH /house/current`. */
export const renameHouseSchema = z.object({
  name: z.string().trim().min(1, "Le nom du foyer est requis").max(100),
});
/** Inferred TS type for {@link renameHouseSchema}'s validated output. */
export type RenameHouseInput = z.infer<typeof renameHouseSchema>;

/** Payload accepted by `POST /house` — same naming rule as renaming one. */
export const createHouseSchema = z.object({
  name: z.string().trim().min(1, "Le nom du foyer est requis").max(100),
});
/** Inferred TS type for {@link createHouseSchema}'s validated output. */
export type CreateHouseInput = z.infer<typeof createHouseSchema>;

/** Payload accepted by `POST /house/join`. Invite codes are always 8 characters — see `house.service.ts`'s generator. */
export const joinHouseSchema = z.object({
  inviteCode: z.string().trim().length(8, "Le code d'invitation doit contenir 8 caractères"),
});
/** Inferred TS type for {@link joinHouseSchema}'s validated output. */
export type JoinHouseInput = z.infer<typeof joinHouseSchema>;

/**
 * Payload accepted by `PATCH /house/current/sources`. Replaces the
 * household's full set of enabled recipe sources (same "replace, not
 * merge" contract as `updateAllergiesSchema`) — an empty array disables
 * every source, which is also this household's starting state (opt-in: no
 * `HouseSource` row means hidden, see schema.prisma).
 */
export const updateHouseSourcesSchema = z.object({
  sourceIds: z.array(z.number().int().positive()),
});
/** Inferred TS type for {@link updateHouseSourcesSchema}'s validated output. */
export type UpdateHouseSourcesInput = z.infer<typeof updateHouseSourcesSchema>;
