/**
 * Vercel Serverless Function Logger
 * Provides structured JSON logging for Vercel API routes
 * Matches the edge function logging pattern for consistency
 */

type LogLevel = 'info' | 'warn' | 'error';

interface LogContext {
  [key: string]: unknown;
}

function formatLog(level: LogLevel, message: string, context?: LogContext): string {
  return JSON.stringify({
    timestamp: new Date().toISOString(),
    level,
    message,
    service: 'vercel-ssrog',
    ...context
  });
}

export const vercelLogger = {
  info: (message: string, context?: LogContext) => {
    console.info(formatLog('info', message, context));
  },
  warn: (message: string, context?: LogContext) => {
    console.warn(formatLog('warn', message, context));
  },
  error: (message: string, context?: LogContext) => {
    console.error(formatLog('error', message, context));
  }
};
