import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
} from '@nestjs/common';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiBearerAuth,
} from '@nestjs/swagger';
import { CombatantsService } from './combatants.service';
import { CreateCombatantDto } from './dto';
import { CurrentUser } from '../../common/decorators/current-user.decorator';

@ApiTags('Battle')
@ApiBearerAuth()
@Controller('campaigns/:campaignId/combatants')
export class CombatantsController {
  constructor(private readonly combatantsService: CombatantsService) {}

  @Get()
  @ApiOperation({ summary: 'Get all NPC/Monster templates for a campaign' })
  @ApiResponse({ status: 200, description: 'List of combatants' })
  async findAll(
    @Param('campaignId') campaignId: string,
    @CurrentUser('id') userId: string,
  ) {
    return this.combatantsService.findAll(campaignId, userId);
  }

  @Get(':combatantId')
  @ApiOperation({ summary: 'Get a specific combatant template' })
  @ApiResponse({ status: 200, description: 'Combatant details' })
  async findOne(
    @Param('campaignId') campaignId: string,
    @Param('combatantId') combatantId: string,
    @CurrentUser('id') userId: string,
  ) {
    return this.combatantsService.findOne(campaignId, combatantId, userId);
  }

  @Post()
  @ApiOperation({ summary: 'Create a new NPC/Monster template' })
  @ApiResponse({ status: 201, description: 'Combatant created' })
  async create(
    @Param('campaignId') campaignId: string,
    @Body() dto: CreateCombatantDto,
    @CurrentUser('id') userId: string,
  ) {
    return this.combatantsService.create(campaignId, dto, userId);
  }

  @Put(':combatantId')
  @ApiOperation({ summary: 'Update a combatant template' })
  @ApiResponse({ status: 200, description: 'Combatant updated' })
  async update(
    @Param('campaignId') campaignId: string,
    @Param('combatantId') combatantId: string,
    @Body() dto: CreateCombatantDto,
    @CurrentUser('id') userId: string,
  ) {
    return this.combatantsService.update(campaignId, combatantId, dto, userId);
  }

  @Delete(':combatantId')
  @ApiOperation({ summary: 'Delete a combatant template' })
  @ApiResponse({ status: 200, description: 'Combatant deleted' })
  async delete(
    @Param('campaignId') campaignId: string,
    @Param('combatantId') combatantId: string,
    @CurrentUser('id') userId: string,
  ) {
    return this.combatantsService.delete(campaignId, combatantId, userId);
  }
}
