import { Controller, Get, Post, Patch, Delete, Param, Body, UseGuards, Request } from '@nestjs/common';
import { JwtAuthGuard } from 'common/guards/jwt-auth.guard';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { BlogCommentService } from './comment.service';
import { CreateBlogCommentDto } from './dto/create-comment.dto';
import { UpdateBlogCommentDto } from './dto/update-comment.dto';

@ApiTags('Blog Comments')
@Controller({ path: 'blogs/:blogId/comments', version: '1' })
export class BlogCommentController {
  constructor(private readonly blogCommentService: BlogCommentService) {}

  // Create a comment on a blog
  @Post()
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'Create a comment on a blog' })
  @ApiResponse({ status: 201, description: 'Comment created successfully.' })
  create(@Body() createBlogCommentDto: CreateBlogCommentDto, @Request() req) {
    const { user } = req;
    return this.blogCommentService.create(createBlogCommentDto, user.id);
  }

  // Get all comments for a specific blog
  @Get()
  @ApiOperation({ summary: 'Get all comments for a blog' })
  @ApiResponse({ status: 200, description: 'List of comments for the blog.' })
  findAll(@Param('blogId') blogId: number) {
    return this.blogCommentService.findAll(blogId);
  }

  // Update a comment by ID
  @Patch(':commentId')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'Update a comment by ID' })
  @ApiResponse({ status: 200, description: 'Comment updated successfully.' })
  @ApiResponse({ status: 404, description: 'Comment not found.' })
  update(@Param('commentId') commentId: string, @Body() updateBlogCommentDto: UpdateBlogCommentDto, @Request() req) {
    return this.blogCommentService.update(commentId, updateBlogCommentDto, req.user);
  }

  // Delete a comment by ID
  @Delete(':commentId')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'Delete a comment by ID' })
  @ApiResponse({ status: 200, description: 'Comment deleted successfully.' })
  @ApiResponse({ status: 404, description: 'Comment not found.' })
  remove(@Param('commentId') commentId: string, @Request() req) {
    return this.blogCommentService.remove(commentId, req.user);
  }
}
