package com.bonus.common.houqin.mq.rabbit.mqtt;

import com.bonus.common.houqin.mq.mqtt.MqttAuth;
import com.bonus.common.houqin.mq.mqtt.MqttAuthCheck;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqttConfiguration {
   private static final Logger log = LoggerFactory.getLogger(MqttConfiguration.class);

   @Bean
   @ConditionalOnMissingBean
   public MqttAuthController mqttAuthController(ObjectProvider<MqttAuthCheck> mqttAuthServiceObjectProvider) {
      return new MqttAuthController((MqttAuthCheck)mqttAuthServiceObjectProvider.getIfUnique(() -> {
         return new MqttAuthCheck() {
            public MqttAuth.Authenticating.Response authc(MqttAuth.Authenticating.Request auth) {
               return MqttAuth.Authenticating.DENY;
            }

            public MqttAuth.Authorizing.Response authz(MqttAuth.Authorizing.Request auth) {
               return MqttAuth.Authorizing.DENY;
            }
         };
      }));
   }
}
