import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { AnalysisService } from './analysis.service';
import { CreateAnalysisDto } from './dto/create-analysis.dto';
import { LookupAnalysisDto } from '../riot/dto/search-riot-user.dto';
import { Query } from '@nestjs/common';

@Controller('v1/analysis')
export class AnalysisController {
  constructor(private readonly analysisService: AnalysisService) {}

  @Post()
  create(@Body() dto: CreateAnalysisDto) {
    return this.analysisService.createAnalysisRequest(dto);
  }

  @Get('lookup')
  lookup(@Query() dto: LookupAnalysisDto) {
    return this.analysisService.lookupLatest(dto);
  }

  @Post('refresh')
  refresh(@Body() dto: CreateAnalysisDto) {
    return this.analysisService.enqueueRefresh(dto);
  }

  @Get('requests/:requestId')
  getRequest(@Param('requestId') requestId: string) {
    return this.analysisService.getRequest(Number(requestId));
  }

  @Get('snapshots/:snapshotId')
  getSnapshot(@Param('snapshotId') snapshotId: string) {
    return this.analysisService.getSnapshot(Number(snapshotId));
  }

  @Get('snapshots/:snapshotId/matches')
  getSnapshotMatches(
    @Param('snapshotId') snapshotId: string,
    @Query('offset') offset?: string,
    @Query('limit') limit?: string,
    @Query('queueFilter') queueFilter?: string,
  ) {
    return this.analysisService.getSnapshotMatches(
      Number(snapshotId),
      Number(offset ?? 0),
      Number(limit ?? 20),
      queueFilter,
    );
  }

  @Get('matches/:participantMatchId')
  getMatchDetail(@Param('participantMatchId') participantMatchId: string) {
    return this.analysisService.getMatchDetail(Number(participantMatchId));
  }
}
