import { Controller, Get, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { CurrentUser, AuthenticatedUser } from '../common/decorators/current-user.decorator';
import { MilestonesService } from './milestones.service';

@UseGuards(JwtAuthGuard)
@Controller('milestones')
export class MilestonesController {
  constructor(private readonly milestonesService: MilestonesService) {}

  @Get()
  async list(@CurrentUser() user: AuthenticatedUser) {
    const earned = await this.milestonesService.getEarnedMilestones(user.userId);
    const all = this.milestonesService.getAllDefs();
    return {
      all,
      earnedKeys: earned.map((m) => m.key),
    };
  }
}
