package com.yingpai.miniapp.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yingpai.miniapp.domain.bo.AgreementConfigBo;
import com.yingpai.miniapp.domain.vo.AgreementConfigVo;
import com.yingpai.miniapp.service.IAgreementConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 协议配置管理
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/miniapp/agreement")
public class AgreementConfigController extends BaseController {

    private final IAgreementConfigService agreementConfigService;

    /**
     * 获取协议配置（后台管理用）
     */
    @SaCheckPermission("miniapp:agreement:list")
    @GetMapping("/list")
    public R<AgreementConfigVo> list() {
        return R.ok(agreementConfigService.getConfig());
    }

    /**
     * 更新用户协议
     */
    @SaCheckPermission("miniapp:agreement:edit")
    @Log(title = "用户协议配置", businessType = BusinessType.UPDATE)
    @PutMapping("/userAgreement")
    public R<Void> updateUserAgreement(@RequestBody AgreementConfigBo bo) {
        AgreementConfigBo updateBo = new AgreementConfigBo();
        updateBo.setUserAgreement(bo.getUserAgreement());
        return toAjax(agreementConfigService.updateConfig(updateBo));
    }

    /**
     * 更新隐私政策
     */
    @SaCheckPermission("miniapp:agreement:edit")
    @Log(title = "隐私政策配置", businessType = BusinessType.UPDATE)
    @PutMapping("/privacyPolicy")
    public R<Void> updatePrivacyPolicy(@RequestBody AgreementConfigBo bo) {
        AgreementConfigBo updateBo = new AgreementConfigBo();
        updateBo.setPrivacyPolicy(bo.getPrivacyPolicy());
        return toAjax(agreementConfigService.updateConfig(updateBo));
    }

}
