const SESSION_KEY = "commercial.wave2.assessment";

export type AssessmentSession = {
  answers: Record<string, unknown>;
  selected_bundle_code?: string | null;
  selected_product_codes?: string[];
  activate_trial?: boolean;
};

export function loadAssessmentSession(): AssessmentSession {
  if (typeof window === "undefined") return { answers: {} };
  try {
    const raw = sessionStorage.getItem(SESSION_KEY);
    return raw ? (JSON.parse(raw) as AssessmentSession) : { answers: {} };
  } catch {
    return { answers: {} };
  }
}

export function saveAssessmentSession(session: AssessmentSession) {
  sessionStorage.setItem(SESSION_KEY, JSON.stringify(session));
}
