package com.njcn.msgpush.module.push.service.channel;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.msgpush.framework.common.util.object.PageUtils;
import com.njcn.msgpush.module.push.controller.admin.channel.vo.ChannelProviderConfigReqVO;
import com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfigDO;
import com.njcn.msgpush.module.push.dal.mysql.channel.ChannelProviderConfigMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChannelProviderConfigServiceImpl extends ServiceImpl<ChannelProviderConfigMapper, ChannelProviderConfigDO> implements ChannelProviderConfigService {

    @Override
    public Page<ChannelProviderConfigDO> listChannelProviderCfg(ChannelProviderConfigReqVO pageReqVO) {
        QueryWrapper<ChannelProviderConfigDO> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(ChannelProviderConfigDO::getChannel, pageReqVO.getChannel());
        return this.page(new Page<>(PageUtils.getPageNum(pageReqVO), PageUtils.getPageSize(pageReqVO)), wrapper);
    }

    @Override
    public List<ChannelProviderConfigDO> getActiveProviders() {
        List<ChannelProviderConfigDO> configDOList = List.of(
                new ChannelProviderConfigDO()
                        .setAppKey("LTAI4FxsR76x2dq3w9c5puUe")
                        .setAppSecret("GxkTR8fsrvHtixTlD9UPmOGli35tZs")
                        .setProviderName("阿里云")
                        .setProviderType("aliyun")
        );
        return configDOList;
    }

    @Override
    public boolean toggleEnableField(String id) {
        return false;
    }

    @Override
    public ChannelProviderConfigDO getByTypeAndChannel(String providerType, String channel) {
        return this.lambdaQuery().eq(ChannelProviderConfigDO::getProviderType, providerType)
                .eq(ChannelProviderConfigDO::getChannel, channel)
                .one();
    }
}
