package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.CouponDto;
import com.mall.coupon.domain.entity.Coupon;
import com.mall.coupon.domain.vo.CouponVo;
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.CouponService;
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")
@RequiredArgsConstructor
public class CouponController {

    private final CouponService couponService;

    @Operation(summary = "分页查询优惠券信息", description = "分页优惠券信息")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<CouponVo>> getCouponPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            CouponDto dto) {
        Page<Coupon> pageParams = new Page<>(page, limit);
        PageResult<CouponVo> pageResult = couponService.getCouponPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加优惠券信息", description = "添加优惠券信息")
    @PostMapping()
    public Result<String> addCoupon(@Valid @RequestBody CouponDto dto) {
            couponService.addCoupon(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新优惠券信息", description = "更新优惠券信息")
    @PutMapping()
    public Result<String> updateCoupon(@Valid @RequestBody CouponDto dto) {
            couponService.updateCoupon(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除优惠券信息", description = "删除优惠券信息")
    @DeleteMapping()
    public Result<String> deleteCoupon(@RequestBody List<Long> ids) {
            couponService.deleteCoupon(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}