package com.xindazhou.business.controller.admin.service.feedback;

import com.xindazhou.business.controller.admin.service.feedback.vo.FeedbackHandleReqVO;
import com.xindazhou.business.controller.admin.service.feedback.vo.FeedbackPageReqVO;
import com.xindazhou.business.controller.admin.service.feedback.vo.FeedbackRespVO;
import com.xindazhou.business.service.service.feedback.FeedbackService;
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;

/**
 * 管理后台 - APP意见反馈 Controller
 *
 * @author xindazhou
 */
@Tag(name = "管理后台 - APP意见反馈")
@RestController("serviceFeedbackController")
@RequestMapping("/admin/service/feedback")
@Validated
@Slf4j
public class FeedbackController {

    @Resource
    private FeedbackService feedbackService;

    @GetMapping("/page")
    @Operation(summary = "获得意见反馈分页列表")
    @PreAuthorize("@ss.hasPermission('service:feedback:query')")
    public CommonResult<PageResult<FeedbackRespVO>> getFeedbackPage(@Valid FeedbackPageReqVO pageReqVO) {
        PageResult<FeedbackRespVO> pageResult = feedbackService.getFeedbackPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获得意见反馈")
    @Parameter(name = "id", description = "反馈ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('service:feedback:query')")
    public CommonResult<FeedbackRespVO> getFeedback(@PathVariable("id") Long id) {
        FeedbackRespVO feedback = feedbackService.getFeedback(id);
        return success(feedback);
    }

    @PostMapping("/{id}/handle")
    @Operation(summary = "处理意见反馈")
    @Parameter(name = "id", description = "反馈ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('service:feedback:handle')")
    public CommonResult<Boolean> handleFeedback(@PathVariable("id") Long id,
                                                 @Valid @RequestBody FeedbackHandleReqVO handleReqVO) {
        feedbackService.handleFeedback(id, handleReqVO);
        return success(true);
    }

}

