/**
 * Tests for src/lib/product-config — request productId resolution + identity exports.
 */

import { describe, it, expect } from 'vitest';
import type { NextRequest } from 'next/server';

import { getRequestProductId, PRODUCT_ID, KNOWN_PRODUCTS } from '@/lib/product-config';

function reqWithHeader(value: string | null): NextRequest {
  return {
    headers: { get: (k: string) => (k.toLowerCase() === 'x-product-id' ? value : null) },
  } as unknown as NextRequest;
}

describe('getRequestProductId', () => {
  it('returns the x-product-id header when present', () => {
    expect(getRequestProductId(reqWithHeader('chronomind'))).toBe('chronomind');
  });

  it('falls back to the configured PRODUCT_ID when the header is absent', () => {
    expect(getRequestProductId(reqWithHeader(null))).toBe(PRODUCT_ID);
  });
});

describe('product identity exports', () => {
  it('exposes a non-empty PRODUCT_ID string', () => {
    expect(typeof PRODUCT_ID).toBe('string');
    expect(PRODUCT_ID.length).toBeGreaterThan(0);
  });

  it('lists known products with unique ids', () => {
    const ids = KNOWN_PRODUCTS.map(p => p.id);
    expect(ids.length).toBeGreaterThan(0);
    expect(new Set(ids).size).toBe(ids.length);
  });
});
