package com.xiaoniu.system.operation.coupon.controller;

import com.xiaoniu.common.core.resdata.Result;
import com.xiaoniu.common.core.resdata.RowsData;
import com.xiaoniu.system.operation.coupon.dto.AddCouponDTO;
import com.xiaoniu.system.operation.coupon.dto.CouponListQueryDTO;
import com.xiaoniu.system.operation.coupon.dto.EditCouponDTO;
import com.xiaoniu.system.operation.coupon.service.ITbCouponService;
import com.xiaoniu.system.operation.coupon.vo.CouponDetailsVO;
import com.xiaoniu.system.operation.coupon.vo.CouponListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author haoxuyang
 * @since 2024-10-17 02:30:09
 */
@Tag(name = "优惠券管理")
@RestController
@RequestMapping("/coupon")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TbCouponController {
    private final ITbCouponService tbCouponService;

    @Operation(summary = "优惠券列表")
    @PostMapping("/list")
    public Result<RowsData<CouponListVO>> list(@RequestBody CouponListQueryDTO dto) {
        return Result.success("查询成功", tbCouponService.couponList(dto));
    }

    @Operation(summary = "新增优惠券")
    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated AddCouponDTO dto) {
        tbCouponService.addCoupon(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "修改优惠券")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody @Validated EditCouponDTO dto) {
        tbCouponService.editCoupon(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "优惠券详情")
    @GetMapping("/details")
    public Result<CouponDetailsVO> details(@RequestParam Long id) {
        return Result.success("查询成功", tbCouponService.details(id));
    }

    @Operation(summary = "删除优惠券")
    @GetMapping("/del")
    public Result<String> delCoupon(@RequestParam Long id) {
        tbCouponService.delCoupon(id);
        return Result.success("操作成功");
    }
}
