package com.czg.controller.admin;

import com.czg.annotation.SaAdminCheckPermission;
import com.czg.market.dto.ChatCouponDTO;
import com.czg.market.dto.MkShopCouponRecordDTO;
import com.czg.market.entity.ChatCoupon;
import com.czg.market.service.ChatCouponService;
import com.czg.market.vo.ChatCouponVO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 群聊优惠券活动
 *
 * @author ww
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/admin/chat/coupon")
public class AChatCouponController {
    @Resource
    private ChatCouponService chatCouponService;

    /**
     * 群聊优惠券活动-创建
     */
    @PostMapping("/create")
    @SaAdminCheckPermission(parentName = "群聊优惠券", value = "chat:coupon:create", name = "群聊优惠券活动-创建")
    public CzgResult<ChatCoupon> createChatCoupon(@RequestBody @Validated ChatCouponDTO chatCoupon) {
        Long shopId = StpKit.USER.getShopId();
        ChatCoupon coupon = chatCouponService.createChatCoupon(shopId, chatCoupon);
        return CzgResult.success(coupon);
    }

    /**
     * 群聊优惠券活动-分页查询
     */
    @GetMapping("/page")
    @SaAdminCheckPermission(parentName = "群聊优惠券", value = "chat:coupon:page", name = "群聊优惠券活动-分页查询")
    public CzgResult<Page<ChatCouponVO>> pageChatCoupon(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                        @RequestParam(required = false, defaultValue = "10") Integer size,
                                                        @RequestParam(required = false) Integer status) {
        Long shopId = StpKit.USER.getShopId();
        return CzgResult.success(chatCouponService.pageChatCoupon(shopId, page, size, status));
    }

    /**
     * 群聊优惠券活动-失效
     */
    @DeleteMapping("/expired/{id}")
    @SaAdminCheckPermission(parentName = "群聊优惠券", value = "chat:coupon:expired", name = "群聊优惠券活动-失效")
    public CzgResult<Boolean> expiredChatCoupon(@PathVariable Long id) {
        Long shopId = StpKit.USER.getShopId();
        return CzgResult.success(chatCouponService.expiredChatCoupon(shopId, id));
    }

    /**
     * 群聊优惠券活动-发放记录
     */
    @GetMapping("/record")
    @SaAdminCheckPermission(parentName = "群聊优惠券", value = "chat:coupon:record", name = "群聊优惠券活动-发放记录")
    public CzgResult<Page<MkShopCouponRecordDTO>> grantChatCouponRecord(@RequestParam Long id,
                                                                        @RequestParam(required = false) Integer status,
                                                                        @RequestParam(required = false, defaultValue = "1") Integer page,
                                                                        @RequestParam(required = false, defaultValue = "10") Integer size) {
        return CzgResult.success(chatCouponService.grantChatCouponRecord(id, status, page, size));
    }


}
