package ui

import (
	"context"

	"git.wntrmute.dev/mc/mcias/internal/token"
)

// uiContextKey is the unexported type for UI context values, preventing
// collisions with keys from other packages.
type uiContextKey int

const (
	uiClaimsKey uiContextKey = iota
)

// contextWithClaims stores validated JWT claims in the request context.
func contextWithClaims(ctx context.Context, claims *token.Claims) context.Context {
	return context.WithValue(ctx, uiClaimsKey, claims)
}

// claimsFromContext retrieves the JWT claims stored by requireCookieAuth.
// Returns nil if no claims are present (unauthenticated request).
func claimsFromContext(ctx context.Context) *token.Claims {
	c, ok := ctx.Value(uiClaimsKey).(*token.Claims)
	if !ok {
		return nil
	}
	return c
}
