package com.dora.controller;

import com.dora.common.Result;
import com.dora.dto.PlazaWorkReportDto;
import com.dora.service.PlazaWorkReportService;
import com.dora.util.SecurityUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 广场作品投诉控制器（用户端）
 * 
 * @author 1818AI
 * @since 2025-11-14
 */
@Slf4j
@RestController
@RequestMapping("/user/plaza/reports")
@Tag(name = "广场作品投诉", description = "用户端API - 投诉广场作品")
@RequiredArgsConstructor
public class PlazaWorkReportController {

    private final PlazaWorkReportService reportService;

    /**
     * 提交投诉
     */
    @PostMapping("/submit")
    @Operation(
        summary = "提交投诉", 
        description = "对广场作品进行投诉，每个用户每天最多投诉10次，不能投诉自己的作品，不能重复投诉同一作品"
    )
    public Result<PlazaWorkReportDto.ReportResponse> submitReport(
            @Valid @RequestBody PlazaWorkReportDto.SubmitReportRequest request) {
        try {
            Long userId = SecurityUtil.getCurrentUserId();
            PlazaWorkReportDto.ReportResponse response = reportService.submitReport(userId, request);
            return Result.success(response);
        } catch (Exception e) {
            log.error("提交投诉失败", e);
            return Result.error(e.getMessage());
        }
    }

    /**
     * 查询我的投诉列表
     */
    @GetMapping("/my")
    @Operation(
        summary = "查询我的投诉列表", 
        description = "查询当前用户提交的所有投诉记录"
    )
    public Result<PlazaWorkReportDto.ReportListResponse> getMyReports(
            @Parameter(description = "页码", example = "1")
            @RequestParam(defaultValue = "1") Integer page,
            
            @Parameter(description = "每页数量", example = "10")
            @RequestParam(defaultValue = "10") Integer size) {
        
        try {
            Long userId = SecurityUtil.getCurrentUserId();
            PlazaWorkReportDto.ReportListResponse response = reportService.getMyReports(userId, page, size);
            return Result.success(response);
        } catch (Exception e) {
            log.error("查询投诉列表失败", e);
            return Result.error(e.getMessage());
        }
    }
}

