import { Controller, Get, Logger, Put, Res } from '@nestjs/common'

import { FastifyReply } from 'fastify'

import { TestDataService } from './test-data.service'

@Controller('test')
export class E2EController {
  private readonly logger = new Logger(E2EController.name)
  constructor(private readonly testData: TestDataService) {}

  @Put('reset')
  reset(@Res({ passthrough: true }) res: FastifyReply): void {
    if (this.testData.config.isStateful === false) {
      res.status(404).send('Cannot reset stateless backend')
      return
    }

    this.testData.resetTestData()

    res.status(200).send('OK')
  }

  @Get('mode')
  getMode(): { mode: string } {
    const backendMode = this.testData.config.isStateful ? 'stateful' : 'stateless'

    return { mode: backendMode }
  }
}
