'use strict';

/*
 *+------------------------------------------------------------------------+
 *| Licensed Materials - Property of IBM
 *| IBM Cognos Products: Dashboard
 *| (C) Copyright IBM Corp. 2014, 2020
 *|
 *| US Government Users Restricted Rights - Use, duplication or disclosure
 *| restricted by GSA ADP Schedule Contract with IBM Corp.
 *+------------------------------------------------------------------------+
 */

define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../dataSources/utils/DatasourceUtil', 'dashboard-analytics/util/DashboardFormatter'], function (Class, DatasourceUtil, Formatter) {
	'use strict';

	/**
  * INTENT: The VisAPI is the topmost API to operations that have to do with mappings, slots, or data
  * (the mapping AND data portions of the spec).
  */

	var VisAPI = Class.extend({

		// constructor
		init: function init(args) {
			VisAPI.inherited('init', this, arguments);
			this._intialize(args);
			this.flag = 'VisAPI';
		},

		destroy: function destroy() {
			this._clear();
			if (this.visModelManager) {
				this.visModelManager.remove();
				this.visModelManager = null;
			}
			VisAPI.inherited('destroy', this, arguments);
		},

		reIntialize: function reIntialize(options) {
			this._clear();
			if (this.visRenderSupport) {
				this.visRenderSupport.clear();
				this.visRenderSupport = null;
			}
			this._intialize(options);
		},
		_clear: function _clear() {
			if (this.visFilterSupport) {
				this.visFilterSupport = null;
			}
			if (this.visConditionsSupport) {
				this.visConditionsSupport.destroy();
				this.visConditionsSupport = null;
			}
			if (this.visPropertySupport) {
				this.visPropertySupport.remove();
				this.visPropertySupport = null;
			}
			if (this.visModelManagerLEFTOVER) {
				this.visModelManagerLEFTOVER = null;
			}
		},
		_intialize: function _intialize(args) {
			var visModelManager = this.visModelManager = args.visModelManager;
			var visRenderSupport = this.visRenderSupport = args.visRenderSupport;
			var visFilterSupport = this.visFilterSupport = args.visFilterSupport;
			var visConditionsSupport = this.visConditionsSupport = args.visConditionsSupport;
			var visPropertySupport = this.visPropertySupport = args.visPropertySupport;
			var ownerWidget = args.ownerWidget;
			var visModelManagerLEFTOVER = this.visModelManagerLEFTOVER = args.visModelManagerLEFTOVER;

			this.visQuerySupport = args.visQuerySupport;

			this.getVisId = visModelManager.getVisId.bind(visModelManager);
			this.getSuppressViewAnimations = visModelManager.getSuppressViewAnimations.bind(visModelManager);
			this.getModule = visModelManager.getModule.bind(visModelManager);
			this.getMetadataColumn = visModelManager.getMetadataColumn.bind(visModelManager);
			this.getMetadataManager = visModelManager.getMetadataManager.bind(visModelManager);
			this.getUsedMetadataColumns = visModelManager.getUsedMetadataColumns.bind(visModelManager);
			this.getInvalidReason = visModelManager.getInvalidReason.bind(visModelManager);
			this.setInvalidReason = visModelManager.setInvalidReason.bind(visModelManager);
			this.clearModelInvalid = visModelManager.clearModelInvalid.bind(visModelManager);
			this.getDefinition = visModelManager.getDefinition.bind(visModelManager);
			this.getTitle = visModelManager.getTitle.bind(visModelManager);
			this.setTitle = visModelManager.setTitle.bind(visModelManager);
			this.isFilterEditable = visModelManager.isFilterEditable.bind(visModelManager);
			this.getShowTitle = visModelManager.getShowTitle.bind(visModelManager);
			this.supportsSortAction = visModelManager.supportsSortAction.bind(visModelManager);
			this.supportsFormatAction = visModelManager.supportsFormatAction.bind(visModelManager);
			this.supportsBinAction = visModelManager.supportsBinAction.bind(visModelManager);
			this.supportsCustomGroupAction = visModelManager.supportsCustomGroupAction.bind(visModelManager);
			this.supportsMaintainAxisScale = visModelManager.supportsMaintainAxisScale.bind(visModelManager);
			this.getListenForPropChangesFromDefinition = visModelManager.getListenForPropChangesFromDefinition.bind(visModelManager);

			this.getFormatter = function () {
				return Formatter;
			};

			// Vis Interactivity settings
			this.getInteractivitySettings = ownerWidget.getInteractivitySettings.bind(ownerWidget);

			this.isOptimizeForSize = ownerWidget.isOptimizeForSize.bind(ownerWidget);

			//SLOTS AND MAPPINGS =======================================
			this.swapSlots = visModelManager.swapSlots.bind(visModelManager);

			this.getDataSlots = visModelManager.getDataSlots.bind(visModelManager);
			this.getLayers = visModelManager.getLayers && visModelManager.getLayers.bind(visModelManager);
			this.getDefaultLayer = visModelManager.getDefaultLayer && visModelManager.getDefaultLayer.bind(visModelManager);
			this.getDataSlotById = visModelManager.getDataSlotById.bind(visModelManager);
			this.getDataItemSlotAndIndex = visModelManager.getDataItemSlotAndIndex.bind(visModelManager);
			this.filterSlotDataItems = visModelManager.filterSlotDataItems.bind(visModelManager);
			this.isMappingEmpty = visModelManager.isMappingEmpty.bind(visModelManager);
			this.getConditions = visModelManager.getConditions.bind(visModelManager);
			this.isDataItemMapped = visModelManager.isDataItemMapped.bind(visModelManager);
			this.hasBinnedDataItems = visModelManager.hasBinnedDataItems.bind(visModelManager);
			this.isIgnoreDefaultSlotSort = visModelManager.isIgnoreDefaultSlotSort.bind(visModelManager);
			//QUERY DEPENDENCIES....
			this.getQueryAPI = this.visQuerySupport.getAPI.bind(this.visQuerySupport);
			this.getQueryManager = this.visQuerySupport.getQueryManager.bind(this.visQuerySupport);
			this.getQueryResults = this.visQuerySupport.getQueryResults.bind(this.visQuerySupport);
			this.getQueryExecution = this.visQuerySupport.getQueryExecution.bind(this.visQuerySupport);
			this.whenQueryResultsReady = this.visQuerySupport.whenQueryResultsReady.bind(this.visQuerySupport);
			this.whenColumnsMinMaxQueryReady = this.visQuerySupport.whenColumnsMinMaxQueryReady.bind(this.visQuerySupport);
			this.whenDataItemsMinMaxQueryReady = this.visQuerySupport.whenDataItemsMinMaxQueryReady.bind(this.visQuerySupport);
			this.queryChanged = this.visQuerySupport.queryChanged.bind(this.visQuerySupport);

			//ANNOTATIONS SUPPORT
			this.getAnnotations = visModelManager.getAnnotations.bind(visModelManager);
			this.setAnnotations = visModelManager.setAnnotations.bind(visModelManager);
			this.whenAnnotatedResultsReady = this.visQuerySupport.whenAnnotatedResultsReady.bind(this.visQuerySupport);
			this.getSmartAnnotationsManger = this.visQuerySupport.getSmartAnnotationsManger.bind(this.visQuerySupport);
			this.getEnabledAnnotations = this.visQuerySupport.getEnabledAnnotations.bind(this.visQuerySupport);
			this.getAllSuggestedAnnotations = this.visQuerySupport.getAllSuggestedAnnotations.bind(this.visQuerySupport);
			this.areThereValidInsights = this.visQuerySupport.areThereValidInsights.bind(this.visQuerySupport);
			this.areThereValidFPDMessages = this.visQuerySupport.areThereValidFPDMessages.bind(this.visQuerySupport);
			this.resetAnnotations = this.visQuerySupport.resetAnnotations.bind(this.visQuerySupport);
			this.setAnnotationMessages = this.visQuerySupport.setAnnotationMessages.bind(this.visQuerySupport);
			this.clearInsightsIndicatorMessages = this.visQuerySupport.clearInsightsIndicatorMessages.bind(this.visQuerySupport);

			//FORECASTING SUPPORT
			this.whenPredictIsReady = this.visQuerySupport.whenPredictIsReady.bind(this.visQuerySupport);

			//POSSIBLE KEY DRIVER SUPPORT
			this.executeFastPatternDetectionRequest = this.visQuerySupport.executeFastPatternDetectionRequest.bind(this.visQuerySupport);
			this.getPossibleKeyDrivers = visModelManager.getPossibleKeyDrivers.bind(visModelManager);
			this.setPossibleKeyDrivers = visModelManager.setPossibleKeyDrivers.bind(visModelManager);
			this.whenPossibleKeyDriversAreReady = this.visQuerySupport.whenPossibleKeyDriversAreReady.bind(this.visQuerySupport);
			this.whenPossibleKeyDriversQueryIsReady = this.visQuerySupport.whenPossibleKeyDriversQueryIsReady.bind(this.visQuerySupport);
			this.getPossibleKeyDriversDisplayState = this.visQuerySupport.getPossibleKeyDriversDisplayState.bind(this.visQuerySupport);
			this.getNewPossibleKeyDriversForTargetId = this.visQuerySupport.getNewPossibleKeyDriversForTargetId.bind(this.visQuerySupport);
			this.possibleKeyDriverSelectionStateChanged = this.visQuerySupport.possibleKeyDriverSelectionStateChanged.bind(this.visQuerySupport);
			this.getEnabledPossibleKeyDrivers = this.visQuerySupport.getEnabledPossibleKeyDrivers.bind(this.visQuerySupport);
			this.getPossibleKeyDriversErrorState = this.visQuerySupport.getPossibleKeyDriversErrorState.bind(this.visQuerySupport);

			//RENDER SUPPORT API's ==============================================================
			this.getRenderer = visRenderSupport.getRenderer.bind(visRenderSupport);
			this.getRenderSequence = visRenderSupport.getRenderSequence.bind(visRenderSupport);
			this.getPreferredSize = visRenderSupport.getPreferredSize.bind(visRenderSupport);
			this.renderComplete = visRenderSupport.renderComplete.bind(visRenderSupport);
			this.renderCompleteBeforeAnimation = visRenderSupport.renderCompleteBeforeAnimation.bind(visRenderSupport);
			this.resize = visRenderSupport.resize.bind(visRenderSupport); //function(newWidth, newHeight)
			this.reRender = visRenderSupport.reRender.bind(visRenderSupport); //function(extraInfo)
			this.mapVizRenderForPrint = visRenderSupport.mapVizRenderForPrint.bind(visRenderSupport);

			//FILTER SUPPORT API's =================================================
			this.selectData = visFilterSupport.select.bind(visFilterSupport);
			this.supportsFilterOnColumn = visFilterSupport.supportsFilterOnColumn.bind(visFilterSupport);
			this.getPendingFilters = visFilterSupport.getPendingFilters.bind(visFilterSupport);
			this.getActiveFilters = visFilterSupport.getActiveFilters.bind(visFilterSupport);
			this.getPageContextAPI = visFilterSupport.getPageContextAPI.bind(visFilterSupport);
			this.getFilterInfo = visFilterSupport.getFilterInfo.bind(visFilterSupport);
			this.setSynchronizeDataFilters = visFilterSupport.setSynchronizeDataFilters.bind(visFilterSupport);
			this.setPendingFilters = visFilterSupport.setPendingFilters.bind(visFilterSupport);
			this.getLocalFiltersList = visFilterSupport.getLocalFiltersList.bind(visFilterSupport);
			this.validateFilters = visFilterSupport.validateFilters.bind(visFilterSupport);
			this.cleanUpMissingFilters = visFilterSupport.cleanUpMissingFilters.bind(visFilterSupport);
			this.getAllFiltersAsLocalFiltersForPinning = visFilterSupport.getAllFiltersAsLocalFiltersForPinning.bind(visFilterSupport);
			this.getLocalFilterAndTopBottomInfo = visFilterSupport.getLocalFilterAndTopBottomInfo.bind(visFilterSupport);
			this.clearSelectionsByDataItemIds = visFilterSupport.clearSelectionsByDataItemIds.bind(visFilterSupport);

			//showby
			this.getSelectionAsLocalFilters = visFilterSupport.getSelectionAsLocalFilters.bind(visFilterSupport);
			this.clearSelectionsUsedForShowBy = visFilterSupport.clearSelectionsUsedForShowBy.bind(visFilterSupport);

			//DRILL - TOPN
			this.getDrillInfo = visFilterSupport.getDrillInfo.bind(visFilterSupport);
			this.getTopBottomInfo = visFilterSupport.getTopBottomInfo.bind(visFilterSupport);

			//CONDITIONAL FORMAT
			this.hasHeatByItem = visConditionsSupport.hasHeatByItem.bind(visConditionsSupport);
			this.getConditionalMinMaxValue = visConditionsSupport.getConditionalMinMaxValue.bind(visConditionsSupport);
			this.createDefaultConditionalPalette = visConditionsSupport.createDefaultConditionalPalette.bind(visConditionsSupport); // function(min, max, options)
			this.initConditionalPalette = visConditionsSupport.initConditionalPalette.bind(visConditionsSupport);
			this.updateConditionalPalette = visConditionsSupport.updateConditionalPalette.bind(visConditionsSupport);
			this.getConditionalPaletteLength = visConditionsSupport.getConditionalPaletteLength.bind(visConditionsSupport);

			//PROPERTY SUPPORT ==========================================
			this.getPropertyValue = visPropertySupport.getPropertyValue.bind(visPropertySupport);
			this.getPropertyById = visPropertySupport.getPropertyById.bind(visPropertySupport);
			this.getProperties = visPropertySupport.getProperties.bind(visPropertySupport);
			this.getVisPropertiesCSSProxy = visPropertySupport.getVisPropertiesCSSProxy.bind(visPropertySupport);

			//VizDef METADATA SUPPORT ==========================================
			this.getMetaDataValue = visModelManager.getMetaDataValue.bind(visModelManager);

			//WIDGET-TO-WIDGET FILTER apis....
			this.getLocalFilters = visModelManager.getLocalFilters.bind(visModelManager);

			//EVENT apis
			this.onChangeTheme = visRenderSupport.onChangeTheme.bind(visRenderSupport);

			this.clearError = ownerWidget.clearError.bind(ownerWidget);
			this.getScope = ownerWidget.getScope.bind(ownerWidget);
			this.getEventGroupId = ownerWidget.getEventGroupId.bind(ownerWidget);
			this.getWidgetId = ownerWidget.getId.bind(ownerWidget);
			this.getDecoratorAPI = ownerWidget.getDecoratorAPI.bind(ownerWidget);
			this.getDecoratorAPIs = ownerWidget.getDecoratorAPIs.bind(ownerWidget);

			this.on = visModelManager.on.bind(visModelManager);
			this.off = visModelManager.off.bind(visModelManager);

			//Custom Data apis
			this.getCustomDataDecoration = visModelManagerLEFTOVER.getCustomDataDecoration.bind(visModelManagerLEFTOVER);
			this.setCustomDataDecoration = visModelManagerLEFTOVER.setCustomDataDecoration.bind(visModelManagerLEFTOVER);
			this.getDecoratedCustomData = visModelManagerLEFTOVER.getDecoratedCustomData.bind(visModelManagerLEFTOVER);
			this.getCustomData = visModelManagerLEFTOVER.getCustomData.bind(visModelManagerLEFTOVER);

			this.getPromptSpec = ownerWidget.getPromptSpec.bind(ownerWidget);
			this.getFredIsRed = ownerWidget.getFredIsRed.bind(ownerWidget);

			// thumbnail generation
			this.generateThumbnail = ownerWidget.generateThumbnail.bind(ownerWidget);
		},


		/**
   * TODO: CLEANUP AREA - This is a 'transitional function' to allow us to move to a visAPI rather then pass around a visModel.
   * 		 The VisAPI should NOT have any data members but the current renderer addresses these members directly.
   * 		 When we copy the renderer, these direct references to members should be the first thing to go.
   */
		setDataMembersTEMPORARILY: function setDataMembersTEMPORARILY(options) {
			this.ownerWidget = options.ownerWidget;
			this.pendingFilters = options.pendingFilters;
			this.localFilters = options.localFilters;
		},

		renderComplete: function renderComplete() {
			throw new Error('VisAPI:renderComplete needs to be implemented');
		}
	});

	return VisAPI;
});
//# sourceMappingURL=VisAPI.js.map