import { Controller, Get, Post, Patch, Body, Param, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger';
import { FeedbackService } from './feedback.service';
import { CreateFeedbackDto } from './dto/create-feedback.dto';
import { Public } from '../../common/decorators/public.decorator';
import { FeedbackRateLimit } from '../../common/decorators/rate-limit.decorator';

@ApiTags('feedback')
@Controller('feedback')
export class FeedbackController {
  constructor(private readonly feedbackService: FeedbackService) {}

  @Public()
  @Post()
  @FeedbackRateLimit()
  @ApiOperation({ summary: '提交反馈' })
  @ApiResponse({ status: 201, description: '反馈提交成功' })
  async create(@Body() dto: CreateFeedbackDto) {
    const feedback = await this.feedbackService.create(dto);
    return { success: true, data: { id: feedback.id } };
  }

  @Get()
  @ApiOperation({ summary: '获取反馈列表' })
  @ApiQuery({ name: 'userId', required: false })
  async findAll(@Query('userId') userId?: string) {
    if (userId) return this.feedbackService.findByUserId(userId);
    return this.feedbackService.findAll();
  }

  @Get('stats')
  @ApiOperation({ summary: '反馈统计' })
  async getStats() {
    return this.feedbackService.getStats();
  }

  @Patch(':id/status')
  @ApiOperation({ summary: '更新反馈状态' })
  async updateStatus(@Param('id') id: string, @Body('status') status: string) {
    return this.feedbackService.updateStatus(id, status);
  }
}
