package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.CouponHistoryDto;
import com.mall.coupon.domain.entity.CouponHistory;
import com.mall.coupon.domain.vo.CouponHistoryVo;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import com.mall.coupon.service.CouponHistoryService;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;

import java.util.List;

/**
 * <p>
 * 优惠券领取历史记录 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-06 11:15:40
 */
@Tag(name = "优惠券领取历史记录", description = "优惠券领取历史记录相关接口")
@RestController
@RequestMapping("/api/coupon/coupon-history")
@RequiredArgsConstructor
public class CouponHistoryController {

    private final CouponHistoryService couponHistoryService;

    @Operation(summary = "分页查询优惠券领取历史记录", description = "分页优惠券领取历史记录")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<CouponHistoryVo>> getCouponHistoryPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            CouponHistoryDto dto) {
        Page<CouponHistory> pageParams = new Page<>(page, limit);
        PageResult<CouponHistoryVo> pageResult = couponHistoryService.getCouponHistoryPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加优惠券领取历史记录", description = "添加优惠券领取历史记录")
    @PostMapping()
    public Result<String> addCouponHistory(@Valid @RequestBody CouponHistoryDto dto) {
            couponHistoryService.addCouponHistory(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新优惠券领取历史记录", description = "更新优惠券领取历史记录")
    @PutMapping()
    public Result<String> updateCouponHistory(@Valid @RequestBody CouponHistoryDto dto) {
            couponHistoryService.updateCouponHistory(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除优惠券领取历史记录", description = "删除优惠券领取历史记录")
    @DeleteMapping()
    public Result<String> deleteCouponHistory(@RequestBody List<Long> ids) {
            couponHistoryService.deleteCouponHistory(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}