package com.eactive.eai.rms.onl.manage.serviceinfo.itsm;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eactive.eai.rms.common.base.BaseService;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
import com.eactive.eai.rms.onl.dashboard.service.Dashboard2RepositoryService;
import com.eactive.eai.rms.onl.manage.serviceinfo.itsm.vo.ItsmRow;
import com.eactive.eai.rms.onl.manage.serviceinfo.itsm.vo.ItsmRows;

@Service
public class ItsmBatchService extends BaseService {
	
	@Autowired
	private Dashboard2RepositoryService dashboardRepoService;
	
	protected ItsmRows getStatus() {
		
		ItsmRows rows = new ItsmRows();
		
		rows.add(newEaiBatchItsm());
		rows.add(newFepBatchItsm());
		
		return rows;
	}
	
	private ItsmRow newEaiBatchItsm() {
	
		try {
			
			DataSourceType batDatasource = DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.BAT);
			String procEaiBatch = dashboardRepoService.getProcEaiBatch();
			ItsmRow eaiBatchRow = ItsmRow.newBatchInstance(batDatasource.getName(), procEaiBatch);
			
			return eaiBatchRow;
			
		} catch (Exception e) {
			
			return new ItsmRow(e);
		}
		
	}
	
	private ItsmRow newFepBatchItsm() {
		
		try {
			
			DataSourceType bapDatasource = DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.BAP);
			String procFepBatch = dashboardRepoService.getProcBatch();
			ItsmRow fepBatchRow = ItsmRow.newBatchInstance(bapDatasource.getName(), procFepBatch);
			
			return fepBatchRow;
			
		} catch (Exception e) {
			
			return new ItsmRow(e);
		}
		
	}

}
