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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jeesharp.business.modules.marketing.couponVerifyLog.application.MemberCouponVerifyLogApplicationService;
import com.jeesharp.business.modules.marketing.couponVerifyLog.entity.MemberCouponVerifyLog;
import com.jeesharp.business.modules.marketing.couponVerifyLog.vo.MemberCouponVerifyLogExportVO;
import com.jeesharp.business.modules.marketing.couponVerifyLog.vo.MemberCouponVerifyLogInfoVO;
import com.jeesharp.business.modules.marketing.couponVerifyLog.vo.MemberCouponVerifyLogListVO;
import com.jeesharp.business.modules.marketing.couponVerifyLog.vo.MemberCouponVerifyLogQueryVO;
import com.jeesharp.framework.office.excel.util.ExcelExportUtil;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import com.jeesharp.framework.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 会员券核销流水 REST 接口，提供分页列表、详情与导出。
 *
 * @author jeesharp
 * @since 2026-06-25
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/marketing/couponVerifyLog/v1")
@Tag(name = "券核销记录", description = "店铺线下券核销流水")
@AllArgsConstructor
public class MemberCouponVerifyLogController extends BaseController {

    private final MemberCouponVerifyLogApplicationService memberCouponVerifyLogApplicationService;

    @ApiOperationSupport(order = 1)
    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('marketing:couponVerifyLog:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<MemberCouponVerifyLogListVO>> list(@RequestBody MemberCouponVerifyLogQueryVO query) {
        Page<MemberCouponVerifyLog> page = new Page<>(query);
        return AjaxResult.okData(memberCouponVerifyLogApplicationService.findPage(page, query));
    }

    @ApiOperationSupport(order = 2)
    @Operation(summary = "详情")
    @PreAuthorize("@ss.hasPermission('marketing:couponVerifyLog:info') or @ss.hasPermission('marketing:couponVerifyLog:list')")
    @GetMapping("info")
    public AjaxResult<MemberCouponVerifyLogInfoVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(memberCouponVerifyLogApplicationService.get(id));
    }

    @ApiOperationSupport(order = 3)
    @Operation(summary = "导出")
    @PreAuthorize("@ss.hasPermission('marketing:couponVerifyLog:export')")
    @PostMapping("export")
    public void export(@RequestBody MemberCouponVerifyLogQueryVO query, HttpServletResponse response) {
        ExcelExportUtil.export(response, MemberCouponVerifyLogExportVO.class,
                memberCouponVerifyLogApplicationService.findList(query), "券核销记录");
    }
}
