package org.dromara.system.controller.system;

import cn.dev33.satoken.stp.StpUtil;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
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.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysComplaintBo;
import org.dromara.system.domain.vo.SysComplaintVo;
import org.dromara.system.service.ISysComplaintService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 投诉建议管理
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/complaint")
public class SysComplaintController extends BaseController {

    private final ISysComplaintService sysComplaintService;

    /**
     * 查询投诉建议列表（管理端）
     */
//     @SaCheckPermission("system:complaint:list")
    @GetMapping("/list")
    public TableDataInfo<SysComplaintVo> list(SysComplaintBo bo, PageQuery pageQuery) {
        return sysComplaintService.queryPageList(bo, pageQuery);
    }

    /**
     * 提交投诉建议（小程序端，需登录）
     */
    @Log(title = "投诉建议", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public R<Void> submit(@Validated @RequestBody SysComplaintBo bo) {
        bo.setCustomerId(LoginHelper.getUserId());
        return toAjax(sysComplaintService.insertByBo(bo));
    }

    /**
     * 删除投诉建议（管理端）
     *
     * @param ids 主键串
     */
//     @SaCheckPermission("system:complaint:remove")
    @Log(title = "投诉建议", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(sysComplaintService.deleteWithValidByIds(List.of(ids)));
    }

}
