import { Controller, Get, UseGuards, Req, Patch, Body, Param, ParseIntPipe, ForbiddenException } from '@nestjs/common';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { EnrollmentsService } from './enrollments.service';

@Controller('me/courses')
@UseGuards(JwtAuthGuard)
export class EnrollmentsController {
  constructor(private service: EnrollmentsService) { }

  @UseGuards(JwtAuthGuard)
  @Get()
  myCourses(@Req() req) {
    return this.service.myCourses(req.user.id);
  }
  @Get(':courseId/content')
  async myCourseContent(
    @Req() req,
    @Param('courseId', ParseIntPipe) courseId: number,
  ) {
    return this.service.getCourseContentForUser(req.user.id, courseId);
  }

  @UseGuards(JwtAuthGuard)
  @Patch('progress')
  updateProgress(@Req() req, @Body() body: { courseId: number; lastLessonId?: number; lastStepId?: number; completed?: boolean }) {
    return this.service.updateProgress(req.user.id, body.courseId, body.lastLessonId, body.lastStepId);
  }
}
