package com.yingpai.miniapp.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yingpai.miniapp.domain.bo.UserFeedbackBo;
import com.yingpai.miniapp.domain.vo.UserFeedbackVo;
import com.yingpai.miniapp.service.IUserFeedbackService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户反馈管理
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/miniapp/feedback")
public class UserFeedbackController extends BaseController {

    private final IUserFeedbackService feedbackService;

    /**
     * 查询用户反馈列表
     */
    @SaCheckPermission("miniapp:feedback:list")
    @GetMapping("/list")
    public TableDataInfo<UserFeedbackVo> list(UserFeedbackBo bo, PageQuery pageQuery) {
        return feedbackService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户反馈列表
     */
    @SaCheckPermission("miniapp:feedback:export")
    @Log(title = "用户反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(UserFeedbackBo bo, HttpServletResponse response) {
        List<UserFeedbackVo> list = feedbackService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户反馈数据", UserFeedbackVo.class, response);
    }

    /**
     * 获取用户反馈详情
     */
    @SaCheckPermission("miniapp:feedback:query")
    @GetMapping("/{id}")
    public R<UserFeedbackVo> getInfo(@PathVariable Long id) {
        return R.ok(feedbackService.queryById(id));
    }

    /**
     * 删除用户反馈（支持单个和批量删除）
     */
    @SaCheckPermission("miniapp:feedback:remove")
    @Log(title = "用户反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(feedbackService.deleteByIds(List.of(ids)));
    }
}
