import type { SafeUserProfile } from "@batch-cooking/shared";

/**
 * Mutable per-scenario signed-in profile, built up across several `Given`
 * steps (see common.steps.ts's "I am signed in as .../my household id
 * is.../my diet id is...") before the final `cy.visit` — each step
 * re-registers the `GET **\/auth/me` intercept with the updated shape, so
 * only the last one (i.e. the fully assembled profile) is ever actually
 * requested by the app. Reset before every scenario by the `Before` hook in
 * common.steps.ts, so scenarios never leak state into one another.
 */
export let currentProfile: SafeUserProfile | null = null;

export function resetProfile() {
  currentProfile = null;
}

export function buildProfile(overrides: Partial<SafeUserProfile> = {}): SafeUserProfile {
  return {
    id: 1,
    firstName: "Alice",
    lastName: "Martin",
    email: "alice@example.com",
    tokenVersion: 0,
    houseId: null,
    dietId: null,
    ...overrides,
  };
}

export function setCurrentProfile(profile: SafeUserProfile) {
  currentProfile = profile;
}
