import {
  Controller,
  Post,
  Get,
  Body,
  UseGuards,
  Req,
  HttpCode,
  HttpStatus,
} from '@nestjs/common';
import { Request } from 'express';
import { CharacterService } from './character.service';
import { CreateCharacterDto } from './dto/create-character.dto';
import { AuthGuard } from '../auth/guards/auth.guard';
import { User } from '../user/user.entity';

@Controller('characters')
@UseGuards(AuthGuard)
export class CharacterController {
  constructor(private readonly characterService: CharacterService) {}

  @Post()
  @HttpCode(HttpStatus.CREATED)
  create(
    @Body() dto: CreateCharacterDto,
    @Req() req: Request & { user: User },
  ) {
    return this.characterService.create(dto, req.user);
  }

  @Get('me')
  findMe(@Req() req: Request & { user: User }) {
    return this.characterService.findByUser(req.user);
  }

  @Get('me/endurance')
  getEndurance(@Req() req: Request & { user: User }) {
    return this.characterService.getEndurance(req.user);
  }
}
