import { Controller, Post, Body } from '@nestjs/common';
import { MockTestAttemptsService } from './mock_test_attempts.service';
import { Public } from '../auth/public.decorator';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiBody } from '@nestjs/swagger';

@ApiTags('mock_test_attempts')
@ApiBearerAuth('access_token')
@Controller('mock_test_attempts')
export class MockTestAttemptsController {
  constructor(
    private readonly mockTestAttemptsService: MockTestAttemptsService,
  ) {}

  @Public()
  @Post('submit')
  @ApiOperation({ summary: 'Submit mock test attempt' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: {
        candidateId: { type: 'number' },
        roleId: { type: 'number' },
        answers: {
          type: 'array',
          items: {
            type: 'object',
            properties: {
              questionId: { type: 'number' },
              selectedOptionId: { type: 'number' },
            },
            required: ['questionId', 'selectedOptionId'],
          },
        },
      },
      required: ['candidateId', 'roleId', 'answers'],
    },
  })
  async submitTest(@Body() body: any) {
    // Expecting candidateId in body for simplicity or from request
    const { candidateId, ...data } = body;
    return this.mockTestAttemptsService.submitTest(candidateId, data);
  }
}
