package tenancy

import "context"

type tenantIDKey struct{}

// WithTenantID stores a tenant ID in the context.
func WithTenantID(ctx context.Context, tenantID string) context.Context {
	if ctx == nil || tenantID == "" {
		return ctx
	}
	return context.WithValue(ctx, tenantIDKey{}, tenantID)
}

// TenantIDFromContext returns the tenant ID from the context.
func TenantIDFromContext(ctx context.Context) string {
	if ctx == nil {
		return ""
	}
	if value := ctx.Value(tenantIDKey{}); value != nil {
		if tenantID, ok := value.(string); ok {
			return tenantID
		}
	}
	return ""
}
