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

import com.jeesharp.business.modules.marketing.api.MarketingMobileApi;
import com.jeesharp.business.modules.marketing.coupon.dto.MarketingCouponVerifyDTO;
import com.jeesharp.business.modules.marketing.coupon.dto.MarketingCouponVerifyRecordsQueryDTO;
import com.jeesharp.business.modules.marketing.coupon.vo.MarketingCouponVerifyResultVO;
import com.jeesharp.business.modules.marketing.couponVerifyLog.vo.MemberCouponVerifyLogListVO;
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 jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * 移动端店员券核销接口：扫码核销与核销记录查询。
 *
 * @author jeesharp
 * @since 2026-06-25
 */
@Slf4j
@RestController
@RequestMapping("${jeesharp.web.mobilePath}/marketing/clerk/coupon")
@Tag(name = "移动端-店员券核销", description = "店铺线下券扫码核销")
@AllArgsConstructor
public class MarketingCouponVerifyMobileController extends BaseMobileController {

    private final MarketingMobileApi marketingMobileApi;

    @Operation(summary = "扫码核销")
    @PostMapping("/verify")
    public AjaxResult<MarketingCouponVerifyResultVO> verify(@RequestBody @Valid MarketingCouponVerifyDTO dto) {
        String operatorMemberId = MemberAuthUtils.getLoginUserId();
        return AjaxResult.ok("核销成功", marketingMobileApi.verifyCoupon(operatorMemberId, dto));
    }

    @Operation(summary = "核销记录")
    @PostMapping("/verifyRecords")
    public AjaxResult<PageRespVO<MemberCouponVerifyLogListVO>> verifyRecords(
            @RequestBody @Valid MarketingCouponVerifyRecordsQueryDTO dto) {
        String operatorMemberId = MemberAuthUtils.getLoginUserId();
        return AjaxResult.okData(marketingMobileApi.pageVerifyRecords(operatorMemberId, dto));
    }
}
