import { Request, Response, NextFunction } from 'express';
import { logger } from '../../config/logger';

export interface AppError extends Error {
  statusCode?: number;
  details?: never;
}

export const errorLogger = (
  err: AppError,
  req: Request,
  res: Response,
  next: NextFunction
) => {
  const errorDetails = {
    message: err.message,
    stack: err.stack,
    timestamp: new Date().toISOString(),
    path: req.path,
    method: req.method,
    statusCode: err.statusCode || 500,
    details: err.details,
  };

  logger.error('Application error:', errorDetails);
  next(err);
};