package com.jeesharp.business.setting.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.jeesharp.business.modules.setting.application.PrivacyPolicyApplicationService;
import com.jeesharp.business.modules.setting.enums.PrivacyPolicyClientEnum;
import com.jeesharp.business.modules.setting.vo.PrivacyPolicyInfoVO;
import com.jeesharp.framework.pojo.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 移动端隐私政策/法律文档接口，按文档编号拉取启用中的正文。
 *
 * <p>类级 {@link SaIgnore} 让本控制器所有方法跳过 Sa-Token 的登录校验
 * （配合 application.yaml 中 sa-interceptor 的 exclude-path-patterns 双重保险，
 *  防止 starter 升级后 yaml 白名单单点失效导致未登录态访问被拦截）。
 *
 * @author jeesharp
 * @since 2026-05-20
 */
@SaIgnore
@RestController
@RequestMapping("${jeesharp.web.mobilePath}/setting/privacyPolicy")
@Tag(name = "移动端-隐私政策")
@AllArgsConstructor
public class PrivacyPolicyMobileController {

    private final PrivacyPolicyApplicationService privacyPolicyApplicationService;

    @Operation(summary = "按编号获取文档", description = "仅返回启用状态；编号示例：PRIVACY、SERVICE。可选参数 client：MP/H5，默认 MP")
    @GetMapping("/info")
    public AjaxResult<PrivacyPolicyInfoVO> info(
            @Parameter(description = "文档编号", required = true, example = "PRIVACY")
            @RequestParam("code") String code,
            @Parameter(description = "展示端：MP/H5，默认 MP（微信小程序）", example = "MP")
            @RequestParam(value = "client", required = false) String client) {
        PrivacyPolicyClientEnum target = PrivacyPolicyClientEnum.fromCode(
                client, PrivacyPolicyClientEnum.DEFAULT_FOR_MOBILE);
        return AjaxResult.okData(privacyPolicyApplicationService.getByDocCode(code, target));
    }
}
