package com.jeesharp.business.setting.controller;

import com.jeesharp.business.modules.setting.application.HomeGridIntroApplicationService;
import com.jeesharp.business.modules.setting.vo.HomeGridIntroMobileDetailVO;
import com.jeesharp.business.modules.setting.vo.HomeGridIntroMobilePageVO;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 小程序首页宫格介绍文章（无需登录浏览）。
 *
 * @author jeesharp
 * @since 2026-05-15
 */
@RestController
@RequestMapping("${jeesharp.web.mobilePath}/setting/homeGridIntro")
@Tag(name = "小程序-宫格介绍")
@AllArgsConstructor
public class HomeGridIntroMobileController {

    private final HomeGridIntroApplicationService homeGridIntroApplicationService;

    @Operation(summary = "介绍列表（分页，已发布）")
    @GetMapping("/list")
    public AjaxResult<HomeGridIntroMobilePageVO> list(
            @RequestParam("quickGridId") String quickGridId,
            @RequestParam(value = "page", defaultValue = "1") long page,
            @RequestParam(value = "pageSize", defaultValue = "15") long pageSize,
            @RequestParam(value = "category", required = false) String category) {
        return AjaxResult.okData(homeGridIntroApplicationService.findPublishedPage(quickGridId, page, pageSize, category));
    }

    @Operation(summary = "介绍详情（已发布）")
    @GetMapping("/detail/{id}")
    public AjaxResult<HomeGridIntroMobileDetailVO> detail(
            @PathVariable("id") String id,
            @RequestParam(value = "quickGridId", required = false) String quickGridId) {
        HomeGridIntroMobileDetailVO data = homeGridIntroApplicationService.getMobileDetail(id, quickGridId);
        if (data == null) {
            return AjaxResult.failMsg("内容不存在或已下线");
        }
        return AjaxResult.okData(data);
    }
}
