package com.jeesharp.business.setting.controller;

import com.jeesharp.business.modules.setting.application.HomeBannerApplicationService;
import com.jeesharp.business.modules.setting.application.MiniHomeShellApplicationService;
import com.jeesharp.business.modules.setting.vo.MiniHomeBannerItemVO;
import com.jeesharp.business.modules.setting.vo.MiniHomeShellVO;
import com.jeesharp.framework.pojo.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
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;

import java.util.List;

/**
 * 小程序首页聚合接口：壳层配置与轮播、公告跑马灯等。
 * <p>统一路径前缀 {@code {mobilePath}/home}（默认 {@code /mobile/home}），与 C 端 {@code apiBaseURL + /home/*} 对齐；
 * 免登录放行见各环境 {@code jeesharp.security.permitAllUrls} 中的 {@code {mobilePath}/home/**}。</p>
 *
 * @author jeesharp
 * @since 2026-05-13
 */
@RestController
@RequestMapping("${jeesharp.web.mobilePath:/mobile}/home")
@Tag(name = "小程序-首页")
@AllArgsConstructor
public class HomeMobileController {

    private final MiniHomeShellApplicationService miniHomeShellApplicationService;
    private final HomeBannerApplicationService homeBannerApplicationService;

    @Operation(summary = "首页壳层（天气文案、公告跑马灯、轮播、宫格、快捷入口、推荐榜 Tab）")
    @GetMapping("/shell")
    public AjaxResult<MiniHomeShellVO> shell() {
        return AjaxResult.okData(miniHomeShellApplicationService.buildShell());
    }

    /**
     * 小程序轮播统一接口（cms_home_banner 启用项）。
     * position=HOME|MALL|FOOD，缺省首页；商城/美食页请传对应 position，勿再使用已废弃的 /mall/banners。
     */
    @Operation(summary = "首页轮播图列表（cms_home_banner，小程序端启用项）", description = "position=HOME|MALL|FOOD，缺省首页")
    @GetMapping("/banners")
    public AjaxResult<List<MiniHomeBannerItemVO>> banners(
        @RequestParam(value = "position", required = false) String position) {
        return AjaxResult.okData(homeBannerApplicationService.listMiniBannersByPosition(position));
    }
}
