package com.xindazhou.business.controller.admin.community.report;

import com.xindazhou.business.controller.admin.community.report.vo.ReportHandleReqVO;
import com.xindazhou.business.controller.admin.community.report.vo.ReportPageReqVO;
import com.xindazhou.business.controller.admin.community.report.vo.ReportRespVO;
import com.xindazhou.business.service.community.report.ReportService;
import com.xindazhou.framework.common.pojo.CommonResult;
import com.xindazhou.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.xindazhou.framework.common.pojo.CommonResult.success;

/**
 * 管理后台 - 举报管理 Controller
 *
 * @author xindazhou
 */
@Tag(name = "管理后台 - 举报管理")
@RestController("communityReportController")
@RequestMapping("/admin/community/report")
@Validated
@Slf4j
public class ReportController {

    @Resource
    private ReportService reportService;

    @GetMapping("/page")
    @Operation(summary = "获得举报分页列表")
    @PreAuthorize("@ss.hasPermission('community:report:query')")
    public CommonResult<PageResult<ReportRespVO>> getReportPage(@Valid ReportPageReqVO pageReqVO) {
        PageResult<ReportRespVO> pageResult = reportService.getReportPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/{reportId}")
    @Operation(summary = "获得举报")
    @Parameter(name = "reportId", description = "举报编号", required = true, example = "RPT001")
    @PreAuthorize("@ss.hasPermission('community:report:query')")
    public CommonResult<ReportRespVO> getReport(@PathVariable("reportId") String reportId) {
        ReportRespVO report = reportService.getReport(reportId);
        return success(report);
    }

    @PostMapping("/{reportId}/handle")
    @Operation(summary = "处理举报")
    @Parameter(name = "reportId", description = "举报编号", required = true, example = "RPT001")
    @PreAuthorize("@ss.hasPermission('community:report:handle')")
    public CommonResult<Boolean> handleReport(@PathVariable("reportId") String reportId,
                                              @Valid @RequestBody ReportHandleReqVO handleReqVO) {
        reportService.handleReport(reportId, handleReqVO);
        return success(true);
    }

}

