import { Body, Controller, Inject, Post, Request, UseGuards } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { OptionalAuthGuard } from 'src/jwt-auth/optional-auth.guard';
import { Logger } from 'winston';
import { LogMessage } from '../models/main.model';
@Controller('log')
export class LogController {
  constructor(@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) {}

  @UseGuards(OptionalAuthGuard)
  @Post()
  log(@Request() req, @Body() message: LogMessage) {
    if (message.severity === 'info') {
      this.logger.info(message.text);
    } else {
      this.logger.error(message.text);
    }
  }
}
