package com.its.wthr.config;

import com.its.app.utils.SysUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Getter
@Setter
@ToString
@Configuration
public class ServerConfig {

	private String bootingDateTime;
	private boolean startSchedule;

	@Value("${application.process.id:EXT01}")
	private String processId;

	@Value("${application.process.name:Weather(Open API) Communication Server}")
	private String processName;

	@Value("${application.process.history:true}")
	private boolean historyProcess;

	@Value("${application.user.id:admin}")
	private String userId;

	@Value("${application.user.pswd:1234}")
	private String userPswd;

	@Value("${application.threads.dbms:#{5}}")
	private int serverDbThreads;

	@Value("${application.threads.data:#{20}}")
	private int serverDataThreads;

	@Value("${application.threads.pool.core-size:#{10}}")
	private int threadPoolCoreSize;

	@Value("${application.threads.pool.max-size:#{50}}")
	private int threadPoolMaxSize;

	@Value("${server.center.bind.addr:0.0.0.0}")
	private String centerBindAddr;
	@Value("${server.center.bind.port:#{6010}}")
	private int centerBindPort;
	@Value("${server.center.dump:false}")
	private boolean centerDump;

	@PostConstruct
	private void init() {
		this.startSchedule = false;

		if (this.threadPoolCoreSize == 0)
			this.threadPoolCoreSize = Runtime.getRuntime().availableProcessors() * 2;
		if (this.centerBindAddr.equals(""))
			this.centerBindAddr = "0.0.0.0";

		this.bootingDateTime = SysUtils.getSysTimeStr();
	}
}
