package de.evoila.cf.broker.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import de.evoila.cf.broker.bean.RabbitMQCredentials;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.cloud.config.java.AbstractCloudConfig;


/**
 * Created by reneschollmeyer on 09.08.17.
 */
@Configuration
class RabbitOnConditionalConfiguration{

      @Configuration
      @Profile({"default", "local"})
      @ConditionalOnBean(RabbitMQCredentials.class)
      static class Default {

            @Autowired
            RabbitMQCredentials conf;
            @Bean
            public CachingConnectionFactory connectionFactory() {
                  CachingConnectionFactory cachingConnectionFactory =
                        new CachingConnectionFactory(conf.getHost(), conf.getPort());
                  cachingConnectionFactory.setUsername(conf.getUsername());
                  cachingConnectionFactory.setPassword(conf.getPassword());
                  cachingConnectionFactory.setVirtualHost(conf.getVhost());
                  return cachingConnectionFactory;
            }

            @Bean
            public AmqpAdmin amqpAdmin() {
                  return new RabbitAdmin(connectionFactory());
            }

            @Bean
            public RabbitTemplate rabbitTemplate() {
                  return new RabbitTemplate(connectionFactory());
            }

      }

      @Configuration
      @Profile("cloud")
      static class Cloud extends AbstractCloudConfig {

            @Bean
            public ConnectionFactory rabbitConnectionFactory() {
                  return connectionFactory().rabbitConnectionFactory();
            }

            @Bean
            public AmqpAdmin amqpAdmin() {
                  return new RabbitAdmin(rabbitConnectionFactory());
            }

            @Bean
            public RabbitTemplate rabbitTemplate() {
                  return new RabbitTemplate(rabbitConnectionFactory());
            }
      }
}

@@ -1919,589 +1919,7 @@
    %7D
-%0A%0A      @Configuration%0A      @Profile(%22cloud%22)%0A      static class Cloud extends AbstractCloudConfig %7B%0A%0A            @Bean%0A            public ConnectionFactory rabbitConnectionFactory() %7B%0A                  return connectionFactory().rabbitConnectionFactory();%0A            %7D%0A%0A            @Bean%0A            public AmqpAdmin amqpAdmin() %7B%0A                  return new RabbitAdmin(rabbitConnectionFactory());%0A            %7D%0A%0A            @Bean%0A            public RabbitTemplate rabbitTemplate() %7B%0A                  return new RabbitTemplate(rabbitConnectionFactory());%0A            %7D%0A      %7D
 %0A%7D%0A

delete unnecessary class