package com.czg.controller.admin;

import com.czg.market.dto.MkShopConsumerCouponDTO;
import com.czg.market.service.MkShopConsumerCouponService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.UpdateGroup;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import com.mybatisflex.core.paginate.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 消费赠券
 * @author ww
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/admin/consumerCoupon")
public class AConsumerCouponController {

    @Resource
    private MkShopConsumerCouponService mkShopConsumerCouponService;

    /**
     * 分页
     */
    @GetMapping("/getConsumerCouponPage")
    public CzgResult<Page<MkShopConsumerCouponDTO>> getConsumerCouponPage(MkShopConsumerCouponDTO param) {
        Long shopId = StpKit.USER.getShopId(0L);
        param.setShopId(shopId);
        return CzgResult.success(mkShopConsumerCouponService.getConsumerCouponPage(param));
    }

    /**
     * 详情
     */
    @GetMapping("/getConsumerCouponById")
    public CzgResult<MkShopConsumerCouponDTO> getConsumerCouponById(Long id) {
        return CzgResult.success(mkShopConsumerCouponService.getConsumerCouponById(id));
    }

    /**
     * 新增
     */
    @PostMapping("/addConsumerCoupon")
    public CzgResult<Void> addConsumerCoupon(@RequestBody MkShopConsumerCouponDTO param) {
        Long shopId = StpKit.USER.getShopId(0L);
        param.setShopId(shopId);
        param.setLeftNum(param.getGiveNum());
        mkShopConsumerCouponService.addConsumerCoupon(param);
        return CzgResult.success();
    }

    /**
     * 更新
     */
    @PutMapping("/updateConsumerCouponById")
    public CzgResult<Void> updateConsumerCouponById(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) MkShopConsumerCouponDTO param) {
        mkShopConsumerCouponService.updateConsumerCouponById(param);
        return CzgResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/deleteConsumerCoupon")
    public CzgResult<Void> deleteConsumerCoupon(Long id) {
        mkShopConsumerCouponService.deleteConsumerCoupon(id);
        return CzgResult.success();
    }
}
