/**
 * 
 */
package org.jim.common.config;

import org.jim.common.ImConfig;
import org.jim.common.http.HttpConfig;
import org.jim.common.utils.Prop;
import org.jim.common.utils.PropUtil;
import org.jim.common.ws.WsServerConfig;
/**
 * @author WChao
 * 2018/08/26
 */
public class PropertyImConfigBuilder extends ImConfigBuilder {

	private Prop prop;

	public PropertyImConfigBuilder(String file) {
		prop = PropUtil.use(file);
	}
	
	@Override
	public ImConfigBuilder configHttp(HttpConfig httpConfig) {
		//html/css/js等的根目录，支持classpath:，也支持绝对路径
		//加载静态资源
		String pageRoot = prop.get("jim.http.page");
		//j-im mvc需要扫描的根目录包
		String[] scanPackages = prop.get("jim.http.scan.packages").split(",");
		httpConfig.setBindPort((prop.getInt("jim.port")));
		//设置web访问路径;
		httpConfig.setPageRoot(pageRoot);
		//不缓存资源;
		httpConfig.setMaxLiveTimeOfStaticRes(prop.getInt("jim.http.max.live.time"));
		//设置j-im mvc扫描目录;
		httpConfig.setScanPackages(scanPackages);
		return this;
	}

	@Override
	public ImConfigBuilder configWs(WsServerConfig wsServerConfig) {
		
		return this;
	}

	@Override
	public ImConfig build() {
		super.build();
		this.setBindIp(prop.get("jim.bind.ip"));
		this.setBindPort(prop.getInt("jim.port"));
		this.setHeartbeatTimeout(prop.getLong("jim.heartbeat.timeout"));
		this.setIsStore(prop.get("jim.store"));
		this.setIsCluster(prop.get("jim.cluster"));
		return conf;
	}
}
