/**
 * Centralized product identity — uses @bytelyst/config shared package.
 *
 * Reads from shared/product.json if available, falls back to env vars / defaults.
 * See: packages/config/src/product-identity.ts
 */

import { loadProductIdentity } from '@bytelyst/config';
import type { NextRequest } from 'next/server';

const identity = loadProductIdentity();

// Single source of truth for the configurable product list (client-safe module).
export {
  KNOWN_PRODUCTS,
  DEFAULT_PRODUCTS,
  parseProductsEnv,
  type Product,
} from './product-constants';

export const PRODUCT_ID = identity.productId;
export const DISPLAY_NAME = identity.displayName;
export const LICENSE_PREFIX = identity.licensePrefix;
export const PACKAGE_NAME = identity.packageName;

/**
 * Extract productId from request header (set by client-side product switcher),
 * falling back to the env-based PRODUCT_ID.
 */
export function getRequestProductId(req: NextRequest): string {
  return req.headers.get('x-product-id') || PRODUCT_ID;
}
