package com.jeesharp.business.modules.coupon.stats.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jeesharp.business.modules.coupon.stats.application.CouponStatsApplicationService;
import com.jeesharp.business.modules.coupon.stats.vo.CouponStatsQueryVO;
import com.jeesharp.business.modules.coupon.stats.vo.CouponStatsResultVO;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 优惠券统计 REST 接口，提供管理端券务概览数据。
 *
 * @author jeesharp
 * @since 2026-07-03
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/coupon/stats/v1")
@Tag(name = "优惠券统计", description = "券模板、领取、发放、核销统计概览")
@AllArgsConstructor
public class CouponStatsController extends BaseController {

    private final CouponStatsApplicationService couponStatsApplicationService;

    @ApiOperationSupport(order = 1)
    @Operation(summary = "统计概览")
    @PreAuthorize("@ss.hasPermission('coupon:stats:overview') or @ss.hasPermission('coupon:couponTemplate:list')")
    @PostMapping("overview")
    public AjaxResult<CouponStatsResultVO> overview(@RequestBody(required = false) CouponStatsQueryVO query) {
        return AjaxResult.okData(couponStatsApplicationService.overview(query));
    }
}
