package com.czg.controller.admin;

import com.czg.account.dto.points.PointsExchangeRecordDTO;
import com.czg.account.param.PointsExchangeRecordParam;
import com.czg.account.service.PointsExchangeRecordService;
import com.czg.account.vo.PointsExchangeSummaryVo;
import com.czg.log.annotation.OperationLog;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.paginate.Page;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 积分兑换记录
 *
 * @author Tankaikai tankaikai@aliyun.com
 * @since 1.0 2025-02-25
 */
@AllArgsConstructor
@RestController
@RequestMapping("/admin/points/exchangeRecord")
public class PointsExchangeRecordController {

    private final PointsExchangeRecordService pointsExchangeRecordService;

    /**
     * 分页
     */
    @GetMapping("page")
    @OperationLog("积分兑换-分页")
    //@SaAdminCheckPermission("pointsExchangeRecord:page")
    public CzgResult<Page<PointsExchangeRecordDTO>> getPointsExchangeRecordPage(PointsExchangeRecordParam param) {
        Page<PointsExchangeRecordDTO> page = pointsExchangeRecordService.getPointsExchangeRecordPage(param);
        return CzgResult.success(page);
    }

    /**
     * 详情
     *
     * @param id 兑换id
     */
    @GetMapping("{id}")
    @OperationLog("积分兑换-详情")
    //@SaAdminCheckPermission("pointsExchangeRecord:info")
    public CzgResult<PointsExchangeRecordDTO> getPointsExchangeRecordById(@PathVariable("id") Long id) {
        PointsExchangeRecordDTO data = pointsExchangeRecordService.getPointsExchangeRecordById(id);
        return CzgResult.success(data);
    }

    /**
     * 核销
     *
     * @param couponCode 兑换码
     */
    @PostMapping("checkout")
    @OperationLog("积分兑换-核销")
    //@SaAdminCheckPermission("pointsExchangeRecord:checkout")
    public CzgResult<Void> checkout(@RequestParam String couponCode) {
        pointsExchangeRecordService.checkout(couponCode);
        return CzgResult.success();
    }

    /**
     * 统计
     */
    @GetMapping("total")
    @OperationLog("积分兑换-统计")
    //@SaAdminCheckPermission("pointsExchangeRecord:total")
    public CzgResult<PointsExchangeSummaryVo> total(PointsExchangeRecordParam param) {
        PointsExchangeSummaryVo data = pointsExchangeRecordService.total(param);
        return CzgResult.success(data);
    }
}