package org.dromara.system.dubbo;

import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.system.api.RemoteConfigService;
import org.dromara.system.api.domain.RemoteSysUnitDomainVo;
import org.dromara.system.api.domain.vo.RemoteSysUserVo;
import org.dromara.system.domain.vo.SysUnitDomainVo;
import org.dromara.system.service.ISysConfigService;
import org.dromara.system.service.ISysUnitDomainService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 配置服务
 *
 * @author Michelle.Chung
 */
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteConfigServiceImpl implements RemoteConfigService {

    private static final Logger log = LoggerFactory.getLogger(RemoteConfigServiceImpl.class);
    private final ISysConfigService configService;

    private final ISysUnitDomainService sysUnitDomainService;

    /**
     * 获取注册开关
     */
    @Override
    public boolean selectRegisterEnabled(String tenantId) {
        return configService.selectRegisterEnabled(tenantId);
    }

    @Override
    public RemoteSysUnitDomainVo queryByDomainName(String domain) {
        log.info("查询域名信息"+domain+"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        SysUnitDomainVo vo =  sysUnitDomainService.queryByDomainName(domain);
        log.info("查询域名信息"+vo+"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        RemoteSysUnitDomainVo domainVo = MapstructUtils.convert(vo, RemoteSysUnitDomainVo.class);
        log.info("查询域名信息"+domainVo+"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        domainVo.setWeChatThirdParams(vo.getWeChatThirdParams());
        return vo != null ? domainVo: null;
    }
}
