package com.czg.controller.admin;

import com.czg.account.dto.ShopShareDTO;
import com.czg.account.service.ShopShareService;
import com.czg.account.vo.ShopShareRecordVO;
import com.czg.account.vo.ShopShareVO;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序分享奖励管理
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/shopShare")
public class ShopShareController {
    @Resource
    private ShopShareService shopShareService;

    /**
     * 获取分享奖励配置
     */
    @SaAdminCheckPermission(value = "shopShare:list", name = "分享好友信息")
    @GetMapping
    public CzgResult<ShopShareVO> get() {
        return CzgResult.success(shopShareService.get(StpKit.USER.getShopId()));
    }

    /**
     * 修改分享奖励配置
     */
    @SaAdminCheckPermission(value = "shopShare:add", name = "分享好友信息添加")
    @PostMapping
    public CzgResult<Boolean> add(@RequestBody @Validated ShopShareDTO shopShareDTO) {
        return CzgResult.success(shopShareService.add(StpKit.USER.getShopId(), shopShareDTO));
    }

    /**
     * 分享奖励记录
     * @param key 邀请人/被邀请人手机号或昵称
     * @param status 0 非新用户 1 未领取 2 已领取 3 已使用 不传递为全部
     * @return 分页数据
     */
    @SaAdminCheckPermission(value = "shopShare:record", name = "分享邀请记录")
    @GetMapping("/record")
    public CzgResult<Page<ShopShareRecordVO>> record(String key, Integer status) {
        return CzgResult.success(shopShareService.recordPage(StpKit.USER.getShopId(), key, status));
    }
}
