import { Body, Controller, Get, Param, Patch, Post, Query } from '@nestjs/common';
import { IncidentsService } from './incidents.service';
import { UpdateIncidentStatusDto } from './incidents.dto';

@Controller('/api/incidents')
export class IncidentsController {
  constructor(private readonly incidentsService: IncidentsService) {}

  @Get()
  getIncidents(
    @Query('status') status?: 'open' | 'acknowledged' | 'resolved',
    @Query('severity') severity?: 'info' | 'warning' | 'major' | 'critical',
    @Query('serviceKey') serviceKey?: string,
    @Query('limit') limit?: string,
  ) {
    return this.incidentsService.getIncidents({
      status,
      severity,
      serviceKey,
      limit: limit ? Number(limit) : undefined,
    });
  }

  @Post('/actions/rebuild')
  rebuildFromCurrentData() {
    return this.incidentsService.rebuildFromCurrentData();
  }

  @Get('/:id')
  getIncidentDetail(@Param('id') id: string) {
    return this.incidentsService.getIncidentDetail(id);
  }

  @Patch('/:id/status')
  updateIncidentStatus(
    @Param('id') id: string,
    @Body() body: UpdateIncidentStatusDto,
  ) {
    return this.incidentsService.updateIncidentStatus(id, body.status);
  }
}
