package com.jeesharp.business.setting.controller;

import com.jeesharp.business.modules.setting.application.AppSplashAdApplicationService;
import com.jeesharp.business.modules.setting.application.OperationPopupApplicationService;
import com.jeesharp.business.modules.setting.vo.OperationPopupClientVO;
import com.jeesharp.business.modules.setting.vo.SplashAdClientBundleVO;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户端免登录展示配置：开屏广告与首页运营弹窗，与 {@code /mobile/noAuth/pay} 等一致走匿名白名单。
 * <p>弹窗路径与《小程序接口文档》§3.31.7 对齐；与开屏同控制器、方法级完整路径，避免仅部分路由被旧构建收录导致 404。</p>
 *
 * @author jeesharp
 * @since 2026-04-21
 */
@RestController
@Tag(name = "用户端-开屏与首页弹窗", description = "开屏整包、首页弹窗投放拉取，无需 access_token")
@AllArgsConstructor
public class SettingSplashAdMobileController {

    private final AppSplashAdApplicationService appSplashAdApplicationService;
    private final OperationPopupApplicationService operationPopupApplicationService;

    @Operation(summary = "拉取开屏整包", description = "按端返回已启用、有效期内的轮播与倒计时、是否可跳过等")
    @GetMapping("${jeesharp.web.mobilePath}/noAuth/setting/splashAd/current")
    public AjaxResult<SplashAdClientBundleVO> current(
            @Parameter(description = "端：默认 WECHAT_MINI")
            @RequestParam(value = "platform", defaultValue = "WECHAT_MINI") String platform) {
        return AjaxResult.okData(appSplashAdApplicationService.getClientBundle(platform));
    }

    @Operation(summary = "首页弹窗列表", description = "返回当前端可用的首页弹窗，按运营配置排序；无配置时为空数组")
    @GetMapping("${jeesharp.web.mobilePath}/noAuth/operation/popup/home")
    public AjaxResult<List<OperationPopupClientVO>> operationPopupHome() {
        return AjaxResult.okData(operationPopupApplicationService.listForWechatMiniHome());
    }
}
