﻿/** 
* namespace FdtWebUi
*/

declare namespace FdtWebUi 
{
	
	/** 
	* Enumeration for expressing the result of an init request. 
	* @enum {string} InitResult
	*/
	const enum InitResult { 
		/* The init request failed. */
		InitFailed, 
		/* The init request  succeeded. */
		InitSucceeded }

	/** 
	* Enumeration for expressing the result of an Close request.
	* @enum {string} CloseResult
	*/
	const enum CloseResult { 
		/* The close request failed. */
		CloseFailed, 
		/* The close request succeeded. */
		CloseSucceeded }

	/** 
	* Main interface of a DTM WebUI 
	*
	* @interface IDtmWebUiFunction
	*/
	interface IDtmWebUiFunction {

		/** 
		* Initialization of the DTM WebUI 
		*
		* @function initAsync
		* @argument {URL} wssUrl - target url of messages (server)
		* @argument {string} systemTag - target of message (DTM)
		* @argument {number} functionId - id of the function
		* @argument {string} initData - initialization of the UI, provided by manifest
		* @argument {string} invokeId - id of UI instance
		* @argument {boolean} showIdentificationArea - initial condition of identification area
		* @argument {callback function} closeMeRequestHandler - event to inform Frame to close the invoking DTM WebUI
		* @argument {string} asyncId-id of the async method call
		* @argument {IDtmWebUiMessaging} webDataConnector - reference to the WebData connector
		* @argument {IWebTrace} trace - reference to the interface used for tracing
		* @argument {callback function} initCallback - asynchronous callback
		*/
		initAsync(
			wssUrl: URL,      // target url of messages (server)
			systemTag: string,   // target of message (DTM)
			functionId: number,  // id of the function
			initData: string,    // initialization of the UI, provided by manifest
			invokeId: string,    // id of UI instance
			showIdentificationArea: boolean,
			closeMeRequestHandler: (this: void, e: Event) => void, // event to inform Frame to close the invoking DTM WebUI
			asyncId: string,    // id of the async method call
			webDataConnector: IDtmWebUiMessaging, // reference to the WebData connector
			trace: IWebTrace, 	// reference to the interface used for tracing
			initCallback: (this: void, asyncId: string, initResult: InitResult) => void // async callback
		): void;

		/** 
		* Closing the DTM WebUI
		*
		* @function closeAsync
		* @argument {string} invokeId - id of UI instance
		* @argument {string} asyncId - id of the async method call
		* @argument {callback function} closeCallback - asynchronous callback
		*/
		closeAsync(
			invokeId: string,    // id of UI instance
			asyncId: string, // id of the async method call
			closeCallback: (this: void, asyncId: string, closeResult: CloseResult, dialogResult?: string ) => void // async callback with optional dialogResult
		): void;

		
	}


	/** 
	* Enumeration for expressing the result of a cancel request. 
	* @enum {string} CancelResult
	*/
	const enum CancelResult { 
		/* The cancel failed. */
		CancelFailed, 
		/* The cancel succeeded. */
		CancelSucceeded 
	}


	/** 
	* Interface used for communication from the DTM WebUI to the DTM BL 
	*
	* @interface IDtmWebUiMessaging
	*/
	interface IDtmWebUiMessaging {

		/** 
		* Initialization of the WebData connector 
		*
		* @function init
		* @argument {URL} wssUrl - target of messages (server)
		* @argument {string} systemTag - target of message (DTM)
		* @argument {number} functionId - id of the function
		* @argument {string} invokeId - id of UI instance
		* @argument {IDtmWebUiMessageEvents} dtmUiReference - Reference to DTM WebUi object that is responsible to handle messaging events
		*/
		init(
			wssUrl: URL, // target of messages (server)
			systemTag: string, // target of message (DTM)
			functionId: number, // id of the function
			invokeId: string, // id of UI instance
			dtmUiReference: IDtmWebUiMessageEvents // Reference to DTM WebUi object that is responsible to handle messaging events
		): void;

		/** 
		* Send request from DTM WebUI to the DTM BL 
		*
		* @function sendMessagesAsync
		* @argument {FdtFitsRequest} data - request containing a list of messages
		* @argument {callback function} sendCallback - asynchronous callback
		*/
		sendMessagesAsync(
			data: FdtFitsRequest, // list of messages
			sendCallback: (this: void, data: FdtFitsResponse) => void // async callback
		): void;

		/** 
		* Cancel the sending of messages 
		* If a send request is canceled, the expectation is that the respective sendCallback is not called. 
		* Still, in some cases it might occur, that the sendCallback is called.
		*
		* @function cancelSendMessagesAsync
		* @argument {string} requestId - id of the send request
		* @argument {callback function} cancelCallback - asynchronous callback
		*/
		cancelSendMessagesAsync(
			requestId: string, 
			cancelCallback: (this: void, requestId: string, cancelResult: CancelResult) => void // async callback
		) : void;

			/** 
		* Termination of the WebData Connector
		*
		* @function terminate
		* @argument {string} invokeId - id of UI instance
		*/
		terminate (
			invokeId: string, // id of the UI instance
		): void;

	}

	/** 
	* Interface of DTM WebUI for receiving events from the DTM BL 
	*
	* @interface IDtmWebUiMessageEvents
	*/
	interface IDtmWebUiMessageEvents {
		/** 
		* Information that a DTM-specific event occured.
		*
		* @function dtmSpecificEventOccured
		* @argument {Array<DtmUiMessage>} data - data that is provided with the event notification
		*/
		dtmSpecificEventOccured(data: Array<DtmUiMessage>) : void;

		/** 
		* Information that a transaction was closed.
		*
		* @function transactionClosed
		*/
		transactionClosed() : void;

		/** 
		* Information that a transaction was commited.
		*
		* @function transactionCommitted
		* @argument {Array<DataSubSetInfo>} data - data that is provided with the event notification
		*/
		transactionCommitted(data: Array<DataSubSetInfo>) : void;

		/** 
		* Information that a transaction was started.
		*
		* @function transactionStarted
		*/
		transactionStarted() : void;
	}

}
