package com.czg.controller.admin;

import com.czg.market.dto.MkShopRechargeDTO;
import com.czg.market.entity.MkShopRechargeFlow;
import com.czg.market.service.MkRechargeFlowService;
import com.czg.market.service.MkShopConsumeDiscountRecordService;
import com.czg.market.service.MkShopRechargeService;
import com.czg.market.vo.MkShopRechargeVO;
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/shopRecharge")
public class ShopRechargeController {
    @Resource
    private MkShopRechargeService shopRechargeService;
    @Resource
    private MkRechargeFlowService rechargeFlowService;

    @Resource
    private MkShopConsumeDiscountRecordService shopConsumeDiscountRecordService;

    /**
     * 配置信息获取
     * 权限标识: activate:list
     */
//    @SaAdminCheckPermission(value = "member:detail", name = "会员配置列表")
    @GetMapping
    public CzgResult<MkShopRechargeVO> detail() {
        if (!StpKit.USER.isManager()) {
            return CzgResult.failure("无权限操作");
        }
        return CzgResult.success(shopRechargeService.detail(StpKit.USER.getShopId()));
    }

    /**
     * 配置信息修改
     * @return 是否成功
     */
//    @SaAdminCheckPermission(value = "member:edit", name = "会员配置列表")
    @PostMapping
    public CzgResult<Boolean> edit(@Validated @RequestBody MkShopRechargeDTO shopRechargeDTO) {
        if (!StpKit.USER.isManager()) {
            return CzgResult.failure("无权限操作");
        }
        return CzgResult.success(shopRechargeService.edit(StpKit.USER.getShopId(), shopRechargeDTO));
    }

    /**
     * 获取充值记录列表
     * @param startTime 开始时间 闭区间
     * @param endTime 结束时间 闭区间
     * @param type 类型
     */
    @GetMapping("/record")
    public Page<MkShopRechargeFlow> getRecord(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) String type) {
        return rechargeFlowService.pageInfo(StpKit.USER.getShopId(), startTime, endTime, type);
    }


}
