package com.eactive.eai.rms.common.datasource;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;



@Service
public class DataSourceTypeManager {

//	public static final String BATCH     = "BATCH";
// 	public static final String EAI_BATCH = "EAI_BATCH";
	public static final String EAI       = "EAI";
	public static final String FEP       = "FEP";
	public static final String MCI       = "MCI";
	public static final String MCU       = "MCU";
	public static final String OPA       = "OPA";
	public static final String BAP       = "BAP";             //일괄
	public static final String BAT       = "BAT";             //배치	

	public static final String MONITORING = "MONITORING";
	public static final String META = "META";
	public static final String IM = "IM";
	public static final String APIGW = "APIGW";

	//스테이징 추가
//	public static final String NSG_STG       = "NSG_STG";
//	public static final String DSG_STG       = "DSG_STG";
//	public static final String GSG_STG       = "GSG_STG";
//	public static final String ZSG_STG       = "ZSG_STG";
//	public static final String ISG_STG       = "ISG_STG";
//	public static final String ASG_STG       = "ASG_STG";  //오픈뱅킹 TOBE 스테이징
//	public static final String MONITORING_STG = "MONITORING_STG";

	//IIAS 통합로그
//	public static final String IT_DSG = "IT_DSG";   //대외망
//	public static final String IT_NSG = "IT_NSG";   //내부망
//	public static final String IT_GSG = "IT_GSG";  //공동망
//	public static final String IT_ZSG = "IT_ZSG";  //DMZ
//	public static final String IT_ASG = "IT_ASG";  //오픈뱅킹


	private static List<DataSourceType> dataSourceTypes = new ArrayList<DataSourceType>();

	public static void setDataSourceTypes(List<DataSourceType> types){
		dataSourceTypes = types;
	}
	public static List<String> getDataSourceTypeNames() {
		ArrayList<String> al = new ArrayList<String>();

		for (DataSourceType d : dataSourceTypes ) {
			al.add(d.getName());
		}
		return al;
	}
	public static DataSourceType getDataSourceType(String name) {
		for (DataSourceType d : dataSourceTypes ) {
			if (name.equals(d.getName())){
				return d;
			}
		}
		return null;
	}
	public static DataSourceType getDataSourceTypeBySchema(String schema) {
		for (DataSourceType d : dataSourceTypes ) {
			if (schema.equals(d.getSchema())){
				return d;
			}
		}
		return null;
	}

	public static DataSourceType getFirstDataSourceType() {
		return dataSourceTypes.get(0);
	}

	public static List<DataSourceType> getDataSourceTypes(){
		return dataSourceTypes;
	}
	public static List<DataSourceType> getDynamicDataSourceTypes(){
		List<DataSourceType> ls = new ArrayList<DataSourceType>();
		for (DataSourceType d : dataSourceTypes ) {
			if (d.isDynamic()){
				ls.add(d);
			}
		}
		return ls;
	}

	public static boolean isDynamicForSchema(String schema){
		boolean isDynamic =false;
		for( DataSourceType d : DataSourceTypeManager.getDynamicDataSourceTypes()){
			if (d.getSchema().equals(schema)){
				isDynamic = true;
				break;
			}
		}
		return isDynamic;
	}
	public static boolean isDynamicForName(String name){
		boolean isDynamic =false;
		for( DataSourceType d : DataSourceTypeManager.getDynamicDataSourceTypes()){
			if (d.getName().equals(name)){
				isDynamic = true;
				break;
			}
		}
		return isDynamic;
	}
	public static List<DataSourceType> getOnlineDataSourceTypes(){
		List<DataSourceType> ls = new ArrayList<DataSourceType>();
		for (DataSourceType d : dataSourceTypes ) {
			if (d.isOnline()){
				ls.add(d);
			}
		}
		return ls;
	}
	public static boolean isOnlineForSchema(String schema){
		boolean isOnline =false;
		for( DataSourceType d : DataSourceTypeManager.getOnlineDataSourceTypes()){
			if (d.getSchema().equals(schema)){
				isOnline = true;
				break;
			}
		}
		return isOnline;
	}
	public static boolean isOnlineForName(String name){
		boolean isOnline =false;
		for( DataSourceType d : DataSourceTypeManager.getOnlineDataSourceTypes()){
			if (d.getName().equals(name)){
				isOnline = true;
				break;
			}
		}
		return isOnline;
	}

	public static boolean isDynamicByName(String name){
		boolean isDynamic =false;
		for( DataSourceType d : DataSourceTypeManager.getDynamicDataSourceTypes()){
			if (d.getName().equals(name)){
				isDynamic = true;
				break;
			}
		}
		return isDynamic;
	}
}
