import { Injectable, NestMiddleware } from '@nestjs/common';

export const LOCALE_KEY = 'locale';

@Injectable()
export class LocaleMiddleware implements NestMiddleware {
  use(req: any, res: any, next: () => void) {
    const locale = 
      req.query.lang as string ||
      req.headers['accept-language']?.split(',')[0]?.split('-')[0] ||
      'en';
    
    req[LOCALE_KEY] = locale;
    next();
  }
}
