package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.EditGroup;
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.web.core.BaseController;
import org.dromara.system.domain.bo.SysAgreementBo;
import org.dromara.system.domain.vo.SysAgreementVo;
import org.dromara.system.service.ISysAgreementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 协议信息管理
 *
 * @author Lion Li
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/agreement")
public class SysAgreementController extends BaseController {

    private final ISysAgreementService sysAgreementService;

    /**
     * 根据ID获取协议详情
     *
     * @param id 协议ID（1=用户协议，2=隐私政策）
     */
    @SaIgnore
    @GetMapping("/{id}")
    public R<SysAgreementVo> getInfo(@NotNull(message = "协议ID不能为空")
                                     @PathVariable Long id) {
        return R.ok(sysAgreementService.queryById(id));
    }

    /**
     * 修改协议内容（前端传入 base64 编码的 HTML 富文本）
     */
//     @SaCheckPermission("system:agreement:edit")
    @Log(title = "协议管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysAgreementBo bo) {
        sysAgreementService.updateByBo(bo);
        return R.ok();
    }

}
