import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import { LoggerService } from 'src/common/logger/logger.service';
import { v4 as uuidv4 } from 'uuid';
import { setValue } from 'express-ctx';

@Injectable()
export class LoggingMiddleware implements NestMiddleware {
    constructor(private readonly loggerService: LoggerService) {}

    use(req: Request, res: Response, next: NextFunction) {
        setValue('session', uuidv4());
        this.loggerService.requestIn(req, res, next)
    }
}