/**
 * Session types for cart/guest identity.
 * useCartSession() returns CartSession. See docs/session-implementation-plan.md.
 */

/** Guest (anonymous) session: cart is keyed by sessionId from cookie. */
export type GuestSession = {
  sessionId: string;
  isGuest: true;
};

/** Authenticated session: cart is keyed by user id; no guest sessionId. */
export type AuthenticatedSession = {
  sessionId: undefined;
  isGuest: false;
};

/** Union: either guest (with sessionId) or authenticated (no sessionId). */
export type CartSession = GuestSession | AuthenticatedSession;

/**
 * Type guard: true if the session is a guest session (has sessionId).
 */
export function isGuestSession(s: CartSession): s is GuestSession {
  return s.isGuest === true;
}
