import { SetMetadata } from "@nestjs/common";

export const IS_PUBLIC_KEY = "isPublic";
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);

/**
 * Marks a route/controller as public *and* disables optional session attachment.
 *
 * Why: some endpoints must be strictly non-personalized for caching/security correctness
 * (e.g. public service catalogs). These endpoints should ignore cookies/tokens entirely.
 */
export const IS_PUBLIC_NO_SESSION_KEY = "isPublicNoSession";
export const PublicNoSession = () => SetMetadata(IS_PUBLIC_NO_SESSION_KEY, true);

/**
 * Marks a route as optionally authenticated.
 *
 * Behavior:
 * - No token: allow request, user = null (200 response, controller handles null user)
 * - Valid token: allow request, user attached (normal authenticated flow)
 * - Invalid/expired token: return 401 (signals "session expired" to client)
 *
 * Use this for "check if I'm logged in" endpoints like /me where:
 * - Unauthenticated users should get a graceful response (not 401)
 * - Users with expired sessions SHOULD get 401 (to trigger re-login)
 */
export const IS_OPTIONAL_AUTH_KEY = "isOptionalAuth";
export const OptionalAuth = () => SetMetadata(IS_OPTIONAL_AUTH_KEY, true);
