package in.gov.digilocker.uidai.logs.config;

import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQConfiguration {
	private static final Logger logger= LoggerFactory.getLogger(RabbitMQConfiguration.class);

	private String rabbitMqHost;
	private int rabbitMqPort;
	private String rabbitMqUsername;
	private String rabbitMqPassword;
	private String rabbitMqExchaneName;
	private String rabbitMqInsertRoutingKey;
	private String rabbitMqUpdateRoutingKey;
	private String rabbitMqInsertType;
	private String rabbitMqUpdateType;
	private int rabbitMqNetworkREcoveryInterval;
	
	
	public RabbitMQConfiguration() {
		Properties prop = new Properties();
		InputStream input = this.getClass().getClassLoader().getResourceAsStream("rabbit-mq.properties");
		try {
			prop.load(input);
		} catch (Exception e) {
			logger.info("Exception in loading resources:- ", e);
		}		
		this.rabbitMqHost = prop.getProperty("rabbit.mq.host").trim();		
		this.rabbitMqPort = null != (prop.getProperty("rabbit.mq.port"))? Integer.parseInt(prop.getProperty("rabbit.mq.port").trim()) : 0;				
		this.rabbitMqUsername = prop.getProperty("rabbit.mq.username").trim();
		this.rabbitMqPassword = prop.getProperty("rabbit.mq.password").trim();
		this.rabbitMqExchaneName = prop.getProperty("rabbit.mq.exchange.name").trim();
		this.rabbitMqInsertRoutingKey = prop.getProperty("rabbit.mq.routing.key.insert").trim()+"_"+prop.getProperty("rabbit.mq.enviournment").trim();
		this.rabbitMqUpdateRoutingKey = prop.getProperty("rabbit.mq.routing.key.update").trim()+"_"+prop.getProperty("rabbit.mq.enviournment").trim();
		this.rabbitMqInsertType = prop.getProperty("rabbit.mq.routing.key.insert.type").trim();
		this.rabbitMqUpdateType = prop.getProperty("rabbit.mq.routing.key.update.type").trim();		
		this.rabbitMqNetworkREcoveryInterval = (null != prop.getProperty("rabbit.mq.network.recovery.interval")) ? Integer.parseInt(prop.getProperty("rabbit.mq.network.recovery.interval").trim()): 0;
	}
	
	public String getRabbitMqHost() {
		return rabbitMqHost;
	}

	public int getRabbitMqPort() {
		return rabbitMqPort;
	}

	public String getRabbitMqUsername() {
		return rabbitMqUsername;
	}

	public String getRabbitMqPassword() {
		return rabbitMqPassword;
	}

	public String getRabbitMqExchaneName() {
		return rabbitMqExchaneName;
	}

	public String getRabbitMqInsertRoutingKey() {
		return rabbitMqInsertRoutingKey;
	}

	public String getRabbitMqUpdateRoutingKey() {
		return rabbitMqUpdateRoutingKey;
	}

	public String getRabbitMqInsertType() {
		return rabbitMqInsertType;
	}

	public String getRabbitMqUpdateType() {
		return rabbitMqUpdateType;
	}

	public int getRabbitMqNetworkREcoveryInterval() {
		return rabbitMqNetworkREcoveryInterval;
	}
}
