/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.rechargeplanconfig.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qcloud.cos.internal.crypto.QCLOUDKMS;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.annotation.CommonNoRepeat;
import vip.xiaonuo.common.pojo.CommonEntity;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.biz.modular.rechargeplanconfig.entity.BizRechargePlanConfig;
import vip.xiaonuo.biz.modular.rechargeplanconfig.param.BizRechargePlanConfigAddParam;
import vip.xiaonuo.biz.modular.rechargeplanconfig.param.BizRechargePlanConfigEditParam;
import vip.xiaonuo.biz.modular.rechargeplanconfig.param.BizRechargePlanConfigIdParam;
import vip.xiaonuo.biz.modular.rechargeplanconfig.param.BizRechargePlanConfigPageParam;
import vip.xiaonuo.biz.modular.rechargeplanconfig.service.BizRechargePlanConfigService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;

import java.util.List;

/**
 * 充值方案配置控制器
 *
 * @author wulei
 * @date 2025/02/04 16:32
 */
@Tag(name = "充值方案配置控制器")
@RestController
@Validated
public class BizRechargePlanConfigController {

    @Resource
    private BizRechargePlanConfigService bizRechargePlanConfigService;

    /**
     * 获取充值方案配置分页
     *
     * @author wulei
     * @date 2025/02/04 16:32
     */
    @Operation(summary = "获取充值方案配置分页")
    @SaCheckPermission("/biz/rechargeplanconfig/page")
    @GetMapping("/biz/rechargeplanconfig/page")
    public CommonResult<Page<BizRechargePlanConfig>> page(BizRechargePlanConfigPageParam bizRechargePlanConfigPageParam) {
        return CommonResult.data(bizRechargePlanConfigService.page(bizRechargePlanConfigPageParam));
    }

    /**
     * 添加充值方案配置
     *
     * @author wulei
     * @date 2025/02/04 16:32
     */
    @Operation(summary = "添加充值方案配置")
    @CommonLog("添加充值方案配置")
    @SaCheckPermission("/biz/rechargeplanconfig/add")
    @PostMapping("/biz/rechargeplanconfig/add")
    public CommonResult<String> add(@RequestBody @Valid BizRechargePlanConfigAddParam bizRechargePlanConfigAddParam) {
        bizRechargePlanConfigService.add(bizRechargePlanConfigAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑充值方案配置
     *
     * @author wulei
     * @date 2025/02/04 16:32
     */
    @Operation(summary = "编辑充值方案配置")
    @CommonLog("编辑充值方案配置")
    @SaCheckPermission("/biz/rechargeplanconfig/edit")
    @PostMapping("/biz/rechargeplanconfig/edit")
    public CommonResult<String> edit(@RequestBody @Valid BizRechargePlanConfigEditParam bizRechargePlanConfigEditParam) {
        bizRechargePlanConfigService.edit(bizRechargePlanConfigEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除充值方案配置
     *
     * @author wulei
     * @date 2025/02/04 16:32
     */
    @Operation(summary = "删除充值方案配置")
    @CommonLog("删除充值方案配置")
    @SaCheckPermission("/biz/rechargeplanconfig/delete")
    @PostMapping("/biz/rechargeplanconfig/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                       List<BizRechargePlanConfigIdParam> bizRechargePlanConfigIdParamList) {
        bizRechargePlanConfigService.delete(bizRechargePlanConfigIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取充值方案配置详情
     *
     * @author wulei
     * @date 2025/02/04 16:32
     */
    @Operation(summary = "获取充值方案配置详情")
    @SaCheckPermission("/biz/rechargeplanconfig/detail")
    @GetMapping("/biz/rechargeplanconfig/detail")
    public CommonResult<BizRechargePlanConfig> detail(@Valid BizRechargePlanConfigIdParam bizRechargePlanConfigIdParam) {
        return CommonResult.data(bizRechargePlanConfigService.detail(bizRechargePlanConfigIdParam));
    }


    /**
     * 获取充值方案配置详情
     *
     * @author wulei
     * @date 2025/02/04 16:32
     */
    @Operation(summary = "启用充值方案")
    @SaCheckPermission("/biz/rechargeplanconfig/enableStatus")
    @CommonLog("启用充值方案")
    @GetMapping("/biz/rechargeplanconfig/enableStatus")
    @CommonNoRepeat
    public CommonResult<String> enableStatus(@Valid BizRechargePlanConfigIdParam bizRechargePlanConfigIdParam) {
        bizRechargePlanConfigService.enableStatus(bizRechargePlanConfigIdParam);
        return CommonResult.ok();
    }

    /**
     * 获取充值方案配置详情
     *
     * @author wulei
     * @date 2025/02/04 16:32
     */
    @Operation(summary = "停用充值方案")
    @SaCheckPermission("/biz/rechargeplanconfig/disableStatus")
    @CommonLog("停用充值方案")
    @GetMapping("/biz/rechargeplanconfig/disableStatus")
    @CommonNoRepeat
    public CommonResult<String> disableStatus(@Valid BizRechargePlanConfigIdParam bizRechargePlanConfigIdParam) {
        bizRechargePlanConfigService.disableStatus(bizRechargePlanConfigIdParam);
        return CommonResult.ok();
    }

    /**
     * 获取充值方案配置分页
     *
     * @author wulei
     * @date 2025/02/04 16:32
     */
    @Operation(summary = "获取充值方案配置分页")
    @GetMapping("/biz/rechargeplanconfig/list")
    public CommonResult<List<BizRechargePlanConfig>> list(BizRechargePlanConfigPageParam bizRechargePlanConfigPageParam) {
        QueryWrapper<BizRechargePlanConfig> queryWrapper = new QueryWrapper<>();
        if(ObjectUtil.isNotEmpty(bizRechargePlanConfigPageParam.getOrgId())){
            queryWrapper.lambda().eq(BizRechargePlanConfig::getOrgId,bizRechargePlanConfigPageParam.getOrgId());
        }
        queryWrapper.lambda().eq(BizRechargePlanConfig::getStatus, "ENABLE");
        queryWrapper.lambda().orderByDesc(CommonEntity::getCreateTime);
        List<BizRechargePlanConfig> planConfigs = bizRechargePlanConfigService.list(queryWrapper);
        return CommonResult.data(planConfigs);
    }


}
