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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jeesharp.business.modules.marketing.coupon.application.MarketingCouponVerifyApplicationService;
import com.jeesharp.business.modules.marketing.coupon.dto.MarketingCouponAdminVerifyDTO;
import com.jeesharp.business.modules.marketing.coupon.vo.MarketingCouponVerifyResultVO;
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 jakarta.validation.Valid;
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 接口（商家小程序 / PC 运营）。
 *
 * @author jeesharp
 * @since 2026-07-03
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/marketing/couponVerify/v1")
@Tag(name = "券扫码核销", description = "店铺线下券管理端扫码核销")
@AllArgsConstructor
public class MarketingCouponVerifyController extends BaseController {

    private final MarketingCouponVerifyApplicationService marketingCouponVerifyApplicationService;

    @ApiOperationSupport(order = 1)
    @Operation(summary = "扫码核销")
    @PreAuthorize("@ss.hasPermission('coupon:memberCoupon:grant') or @ss.hasPermission('marketing:couponVerifyLog:list')")
    @PostMapping("verify")
    public AjaxResult<MarketingCouponVerifyResultVO> verify(@RequestBody @Valid MarketingCouponAdminVerifyDTO dto) {
        return AjaxResult.ok("核销成功", marketingCouponVerifyApplicationService.verifyByAdmin(dto));
    }
}
