package com.hotwj.platform.config.systemAgreement.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.hotwj.platform.config.systemAgreement.domain.bo.HotSystemAgreementBo;
import com.hotwj.platform.config.systemAgreement.domain.vo.HotSystemAgreementVo;
import com.hotwj.platform.config.systemAgreement.service.IHotSystemAgreementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
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.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户隐私政策
 *
 * @author shihongwei
 * @date 2026-01-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/config/systemAgreement")
@Tag(name = "用户隐私政策", description = "用户隐私政策管理")
public class HotSystemAgreementController extends BaseController {

    private final IHotSystemAgreementService hotSystemAgreementService;

    /**
     * 查询用户隐私政策列表
     */
    @SaIgnore
    @GetMapping("/list")
    @Operation(summary = "分页查询用户隐私政策列表")
    public TableDataInfo<HotSystemAgreementVo> list(HotSystemAgreementBo bo, PageQuery pageQuery) {
        return hotSystemAgreementService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户隐私政策列表
     */
    //@SaCheckPermission("config:systemAgreement:export")
    @Log(title = "用户隐私政策", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出用户隐私政策列表")
    public void export(HotSystemAgreementBo bo, HttpServletResponse response) {
        List<HotSystemAgreementVo> list = hotSystemAgreementService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户隐私政策", HotSystemAgreementVo.class, response);
    }

    /**
     * 获取用户隐私政策详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("config:systemAgreement:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取用户隐私政策详细信息")
    public R<HotSystemAgreementVo> getInfo(@NotNull(message = "主键不能为空")
                                           @Parameter(name = "id", description = "主键", required = true, example = "1")
                                           @PathVariable Long id) {
        return R.ok(hotSystemAgreementService.queryById(id));
    }

    /**
     * 新增用户隐私政策
     */
    //@SaCheckPermission("config:systemAgreement:add")
    @Log(title = "用户隐私政策", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增用户隐私政策")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotSystemAgreementBo bo) {
        return toAjax(hotSystemAgreementService.insertByBo(bo));
    }

    /**
     * 修改用户隐私政策
     */
    //@SaCheckPermission("config:systemAgreement:edit")
    @Log(title = "用户隐私政策", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改用户隐私政策")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotSystemAgreementBo bo) {
        return toAjax(hotSystemAgreementService.updateByBo(bo));
    }

    /**
     * 删除用户隐私政策
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("config:systemAgreement:remove")
    @Log(title = "用户隐私政策", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除用户隐私政策")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable Long[] ids) {
        return toAjax(hotSystemAgreementService.deleteWithValidByIds(List.of(ids), true));
    }
}
