package com.jeesharp.business.coupon.controller;

import com.jeesharp.business.modules.coupon.api.MemberCouponMobileApi;
import com.jeesharp.business.modules.coupon.vo.CouponDemoVO;
import com.jeesharp.business.modules.coupon.vo.CouponTemplateQueryVO;
import com.jeesharp.framework.memberauth.utils.MemberAuthUtils;
import com.jeesharp.framework.memberauth.web.BaseMobileController;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.query.PageRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 移动端消费券模板接口（规范路径：{@code /mobile/coupon/couponTemplate/*}），
 * 与领券中心、搜索筛选对齐；未登录时可浏览，已登录时合并个人已领状态。
 *
 * @author jeesharp
 * @since 2026-05-07
 */
@Slf4j
@RestController
@RequestMapping("${jeesharp.web.mobilePath}/coupon/couponTemplate")
@Tag(name = "移动端-消费券模板", description = "消费券模板分页与详情（规范路径）")
@AllArgsConstructor
public class CouponTemplateMobileController extends BaseMobileController {

    private final MemberCouponMobileApi memberCouponMobileApi;

    @Operation(summary = "消费券模板分页列表")
    @PostMapping("/list")
    public AjaxResult<PageRespVO<CouponDemoVO>> list(@RequestBody(required = false) CouponTemplateQueryVO query) {
        CouponTemplateQueryVO q = query != null ? query : new CouponTemplateQueryVO();
        return AjaxResult.okData(memberCouponMobileApi.pageTemplateDemos(MemberAuthUtils.getLoginUserId(), q));
    }

    @Operation(summary = "消费券模板详情")
    @GetMapping("/info")
    public AjaxResult<CouponDemoVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(memberCouponMobileApi.getTemplateDemo(id, MemberAuthUtils.getLoginUserId()));
    }

}
