
package com.cim.idm.wmsextend.generic.util;

import com.cim.idm.framework.action.management.ActionContainerManager.ActionTypeEnum;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.framework.util.time.TimeStampUtil;
import com.cim.idm.framework.util.time.TimeUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


public class EventInfoUtil implements ApplicationContextAware
{
	
	/**
	 * @uml.property  name="applicationContext"
	 * @uml.associationEnd  
	 */
	private ApplicationContext	applicationContext;

	

	/**
	 * @param arg0
	 * @throws BeansException
	 * @uml.property  name="applicationContext"
	 */
	public void setApplicationContext( ApplicationContext arg0 ) throws BeansException
	{
		// TODO Auto-generated method stub
		applicationContext = arg0;
	}
	/*
	* Name : makeEventInfo
	* Desc : This function is makeEventInfo
	* Author : ZXY Systems, Inc
	* Date : 2013.02.19
	*/
	public static EventInfo makeEventInfo( String eventName, String eventUser, String  eventComment,
			String reasonCodeType, String reasonCode, String checkTimekeyValidation)
	{
		EventInfo eventInfo = new EventInfo();
		
		eventInfo.setBehaviorName( "" );
		eventInfo.setEventName( eventName );
		eventInfo.setEventUser( eventUser );

		if (checkTimekeyValidation.equals("N"))
			eventInfo.setCheckTimekeyValidation(false);

		if ( eventComment == null )
			eventComment = "";
		
		eventInfo.setEventComment( eventComment );
		eventInfo.setEventTime( TimeStampUtil.getCurrentTimestamp());
		
		if ( reasonCodeType == null )
			reasonCodeType = "";
		
		eventInfo.setReasonCodeType( reasonCodeType );
		
		if ( reasonCode == null )
			reasonCode = "";
		
		eventInfo.setReasonCode( reasonCode );
		
		return eventInfo;
	}
	/*
	* Name : makeEventInfo
	* Desc : This function is makeEventInfo
	* Author : ZXY Systems, Inc
	* Date : 2013.02.19
	*/
	public static EventInfo makeEventInfo( String eventName, String eventUser, String eventComment, String reasonCodeType, String reasonCode )
	{
		EventInfo eventInfo = new EventInfo();
		
		eventInfo.setBehaviorName("");
		eventInfo.setEventName( eventName );
		eventInfo.setEventUser( eventUser );
		
		if ( eventComment == null )
			eventComment = "";
		
		eventInfo.setEventComment( eventComment );
		eventInfo.setEventTime( TimeStampUtil.getCurrentTimestamp());
		// Do Not Check TimeKey Validation
		eventInfo.setCheckTimekeyValidation(false);
		
		if ( reasonCodeType == null )
			reasonCodeType = "";
		
		eventInfo.setReasonCodeType( reasonCodeType );
		
		if ( reasonCode == null )
			reasonCode = "";
		
		eventInfo.setReasonCode( reasonCode );
		
		return eventInfo;
	}

	/*
	* Name : makeEventInfoWithDBTimeKey
	* Desc : This function is makeEventInfoWithDBTimeKey
	* Author : ZXY Systems, Inc
	* Date : 2018.02.26
	*/
	public static EventInfo makeEventInfoWithDBTimeKey( String eventName, String eventUser, String eventComment, String reasonCodeType, String reasonCode )
	{
		EventInfo eventInfo = new EventInfo();
		
		eventInfo.setBehaviorName("");
		eventInfo.setEventName( eventName );
		eventInfo.setEventUser( eventUser );
		
		if ( eventComment == null )
			eventComment = "";
		
		eventInfo.setEventComment( eventComment );

		// Use makeEventInfoWithDBTimeKey to avoid duplicated EventTimeKey.
		eventInfo.setEventTimeKey(new TimeUtils().getCurrentEventTimeKey());
		eventInfo.setEventTime(new TimeUtils().getTimestampByTimeKey(eventInfo.getEventTimeKey()));
		// Do Not Check TimeKey Validation
		eventInfo.setCheckTimekeyValidation(false);
		
		if ( reasonCodeType == null )
			reasonCodeType = "";
		
		eventInfo.setReasonCodeType( reasonCodeType );
		
		if ( reasonCode == null )
			reasonCode = "";
		
		eventInfo.setReasonCode( reasonCode );
		
		return eventInfo;
	}
	
	
	
	/*
	* Name : makeEventInfo_Glass
	* Desc : This function is makeEventInfo_Glass
	* Author : ZXY Systems, Inc
	* Date : 2013.02.19
	*/
	public static EventInfo makeEventInfo_Glass( String eventName, String eventUser, String eventComment, String reasonCodeType, String reasonCode )
	{
		EventInfo eventInfo = new EventInfo();
		
		eventInfo.setBehaviorName( ActionTypeEnum.action_glass.toString() );
		eventInfo.setEventName( eventName );
		eventInfo.setEventUser( eventUser );
		
		if ( eventComment == null )
			eventComment = "";
		
		eventInfo.setEventComment( eventComment );
		eventInfo.setEventTime( TimeStampUtil.getCurrentTimestamp());
		// Do Not Check TimeKey Validation
		eventInfo.setCheckTimekeyValidation(false);
		
		if ( reasonCodeType == null )
			reasonCodeType = "";
		
		eventInfo.setReasonCodeType( reasonCodeType );
		
		if ( reasonCode == null )
			reasonCode = "";
		
		eventInfo.setReasonCode( reasonCode );
		
		return eventInfo;
	}
	/*
	* Name : makeEventInfo_ExceptAction
	* Desc : This function is makeEventInfo_ExceptAction
	* Author : ZXY Systems, Inc
	* Date : 2013.02.19
	*/
	public static EventInfo makeEventInfo_ExceptAction( String eventName, String eventUser, String eventComment,
			String reasonCodeType, String reasonCode )
	{
		EventInfo eventInfo = new EventInfo();
		
		eventInfo.setBehaviorName(ActionTypeEnum.action_exceptAction.toString() );
		eventInfo.setEventName( eventName );
		eventInfo.setEventUser( eventUser );
		
		if ( eventComment == null )
			eventComment = "";
		
		eventInfo.setEventComment( eventComment );
		eventInfo.setEventTime( TimeStampUtil.getCurrentTimestamp());
		// Do Not Check TimeKey Validation
		eventInfo.setCheckTimekeyValidation(false);
		
		if ( reasonCodeType == null )
			reasonCodeType = "";
		
		eventInfo.setReasonCodeType( reasonCodeType );
		
		if ( reasonCode == null )
			reasonCode = "";
		
		eventInfo.setReasonCode( reasonCode );
		
		return eventInfo;
	}
	/*
	* Name : codeMakeEventInfo
	* Desc : This function is codeMakeEventInfo
	* Author : ZXY Systems, Inc
	* Date : 2013.02.19
	*/
	public static EventInfo codeMakeEventInfo( String eventName, String eventUser, String eventComment,
			String reasonCodeType, String reasonCode )
	{
		EventInfo eventInfo = new EventInfo();
		
		eventInfo.setBehaviorName( "" );
		eventInfo.setEventName( eventName );
		eventInfo.setEventUser( eventUser );
		
		if ( eventComment == null )
			eventComment = "";
		
		eventInfo.setEventComment( eventComment );
		eventInfo.setEventTime( TimeStampUtil.getCurrentTimestamp());
		
		if ( reasonCodeType == null )
			reasonCodeType = "";
		
		eventInfo.setReasonCodeType( reasonCodeType );
		
		if ( reasonCode == null )
			reasonCode = "";
		
		eventInfo.setReasonCode( reasonCode );
		
		return eventInfo;
	}
	
	//initial Input Corning I/F
	public static EventInfo makeEventInfoAddTimekey( String eventName, String eventUser, String eventComment, String reasonCodeType, String reasonCode )
	{
		EventInfo eventInfo = new EventInfo();
		
		eventInfo.setBehaviorName("");
		eventInfo.setEventName( eventName );
		eventInfo.setEventUser( eventUser );
		
		if ( eventComment == null )
			eventComment = "";
		 
		eventInfo.setEventComment( eventComment );
		
		// Do Not Check TimeKey Validation
		eventInfo.setCheckTimekeyValidation(false);
		eventInfo.setEventTimeKey(TimeStampUtils.getLocalCurrentEventTimeKey());

		//20190804 Time Mismatch - Using getTimeStampCheckTimekey
		//eventInfo.setEventTime(TimeStampUtil.getTimestamp(eventInfo.getEventTimeKey()));
		eventInfo.setEventTime(TimeStampUtils.getTimeStampCheckTimekey(eventInfo.getEventTimeKey()));
		
		
		if ( reasonCodeType == null )
			reasonCodeType = "";
		
		eventInfo.setReasonCodeType( reasonCodeType );
		
		if ( reasonCode == null )
			reasonCode = "";
		
		eventInfo.setReasonCode( reasonCode );
		
		return eventInfo;
	}

	public static EventInfo makeEventInfoAddTimekey( String eventName, String eventUser, String eventComment)
	{
		return makeEventInfoAddTimekey(eventName, eventUser, eventComment, null, null);
	}

}
