package com.eactive.eai.rms.onl.tracking.vo;

import java.util.Arrays;

import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;


public class MemStaticsVo {
	
	public final int MAX_LINE = 7 ; // MCI/MCU/EAI/FEP/OPA/APIGW/BAP
	public final int IN   = 0 ;
	public final int OUT  = 1 ;

	private String hostName ; // host name
	private String instName ; // instance name

	public int     procs[]    = {0,0,0,0,0,0,0};
	public int     timeouts[] = {0,0,0,0,0,0,0};
	public int     errors[]   = {0,0,0,0,0,0,0};
	public int     serrors[]  = {0,0,0,0,0,0,0};
	
	public static int getPos(DataSourceType dataSourceType) {
		if( DataSourceTypeManager.MCI.equals(dataSourceType.getName()) ) {  // MCI 대면
			return 0 ;
		}
		if( DataSourceTypeManager.MCU.equals(dataSourceType.getName()) ) {  // MCI 비대명
			return 1 ;
		}
		if( DataSourceTypeManager.EAI.equals(dataSourceType.getName()) ) {  // EAI
			return 2 ;
		}
		if( DataSourceTypeManager.FEP.equals(dataSourceType.getName()) ) {  // FEP
			return 3 ;
		}
		if( DataSourceTypeManager.OPA.equals(dataSourceType.getName()) ) {  // OPA
			return 4 ;
		}
		if( DataSourceTypeManager.APIGW.equals(dataSourceType.getName()) ) {  // APIGW
			return 5 ;
		}
		if( DataSourceTypeManager.BAP.equals(dataSourceType.getName()) ) {  // BAP
			return 6 ;
		}

		return -1 ;
	}
	
	public MemStaticsVo copy() {
		MemStaticsVo vo = new MemStaticsVo();
		vo.hostName = this.hostName;
		vo.instName = this.instName;
		
		for( int i = 0 ; i < MAX_LINE ; i++ ) {
			vo.procs[i] = this.procs[i];
			vo.timeouts[i] = this.timeouts[i];
			vo.errors[i] = this.errors[i];
			vo.serrors[i] = this.serrors[i];
		}
		
		return vo;
	}
	
	public void addProcIn(int cnt) {
		procs[IN] += cnt;
	}
	public void addProcOut(int cnt) {
		procs[OUT] += cnt;
	}

	public void addTimeoutIn(int cnt) {
		timeouts[IN] += cnt;
	}
	public void addTimeoutOut(int cnt) {
		timeouts[OUT] += cnt;
	}

	public void addErrorIn(int cnt) {
		errors[IN] += cnt;
	}
	public void addErrorOut(int cnt) {
		errors[OUT] += cnt;
	}
	
	public void addSysErrorIn(int cnt) {
		serrors[IN] += cnt;
	}
	public void addSysErrorOut(int cnt) {
		serrors[OUT] += cnt;
	}
	
	public int getProcIn() {
		return procs[IN];
	}
	public int getProcOut() {
		return procs[OUT];
	}
		
	public int getTimeoutIn() {
		return timeouts[IN];
	}
	public int getTimeoutOut() {
		return timeouts[OUT];
	}
	
	
	public int getErrorIn() {
		return errors[IN];
	}
	public int getErrorOut() {
		return errors[OUT];
	}
	
	public int getSysErrorIn() {
		return serrors[IN];
	}
	public int getSysErrorOut() {
		return serrors[OUT];
	}
	
	public void add(MemStaticsVo s) {
		if (s != null) {
			for (int i = 0; i < MAX_LINE; i++) {
				procs[i] += s.procs[i];
				timeouts[i] += s.timeouts[i];
				errors[i] += s.errors[i];
				serrors[i] += s.serrors[i];
			}
		}
	}

	public String getHostName() {
		return hostName;
	}
	public void setHostName(String hostName) {
		this.hostName = hostName;
	}
	public String getInstName() {
		return instName;
	}
	public void setInstName(String instName) {
		this.instName = instName;
	}
	public int[] getProcs() {
		return procs;
	}
	public void setProcs(int[] procs) {
		this.procs = procs;
	}
	public int[] getTimeouts() {
		return timeouts;
	}
	public void setTimeouts(int[] timeouts) {
		this.timeouts = timeouts;
	}
	public int[] getErrors() {
		return errors;
	}
	public void setErrors(int[] errors) {
		this.errors = errors;
	}
	public int[] getSerrors() {
		return serrors;
	}
	public void setSerrors(int[] serrors) {
		this.serrors = serrors;
	}
	
	public void setProc(int pos, int cnt) {
		procs[pos] = cnt;
	}
	
	public void setError(int pos, int cnt) {
		errors[pos] = cnt;
	}
	
	public void setTimeout(int pos, int cnt) {
		timeouts[pos] = cnt;
	}
	
	public void setSerror(int pos, int cnt) {
		serrors[pos] = cnt;
	}
	
	
	public int getProcTotal() {
		int total = 0 ;
		for( int i = 0 ; i < MAX_LINE ; i++ ) {
			total += procs[i];
		}
		
		return total;
	}

	public int getErrorTotal() {
		int total = 0 ;
		for( int i = 0 ; i < MAX_LINE ; i++ ) {
			total += errors[i];
		}
		
		return total;
	}
	
	public int getSysErrorTotal() {
		int total = 0 ;
		for( int i = 0 ; i < MAX_LINE ; i++ ) {
			total += serrors[i];
		}
		
		return total;
	}

	public int getTimeoutTotal() {
		int total = 0 ;
		for( int i = 0 ; i < MAX_LINE ; i++ ) {
			total += timeouts[i];
		}
		
		return total;
	}

	@Override
	public String toString() {
		return "MemStaticsVo [IN=" + IN + ", OUT=" + OUT + ", MAX_LINE=" + MAX_LINE
				+ ", errors=" + Arrays.toString(errors) + ", hostName="
				+ hostName + ", instName=" + instName + ", procs="
				+ Arrays.toString(procs) + ", timeouts="
				+ Arrays.toString(timeouts) + ", serrors="
				+ Arrays.toString(serrors) + "]";
	}


	
}
