'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

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

/**
 * Create a public API to a decorator for the n-th vipr dataset
 *
 * @class DecoratorAPI
 * @hideconstructor
 * @classdesc
 */
define([], function () {
	var APISpec = function () {
		function APISpec() {
			_classCallCheck(this, APISpec);
		}

		APISpec.prototype.getAPISpec = function getAPISpec() {
			var _this = this;

			if (!this.apiSpec) {

				var drillGetUndoActions = function drillGetUndoActions() {
					var actionName = void 0;
					var params = void 0;
					var drillDown = _this.getDrillDownValue();
					var drillUp = _this.getDrillUpValue();
					if (!drillDown && !drillUp) {
						actionName = 'clearDrill';
						params = [];
					} else if (drillDown) {
						actionName = 'drillDown';
						params = [drillDown];
					} else if (drillUp) {
						actionName = 'drillUp';
						params = [drillUp];
					}
					return [{
						name: actionName,
						params: params
					}];
				};

				this.apiSpec = {
					name: 'dataitem API',
					features: {
						'Dashboard.Transaction': this.transaction
					},
					events: {
						serializeActions: {
							children: [{
								getObject: function getObject() {
									return _this.unionImpl;
								},
								callStack: [{
									name: 'getUnion',
									params: []
								}]
							}]
						},
						propagationInfo: {
							namespace: this.isRootDataItem() ? 'dataitem' : null,
							info: {
								dataItemId: this.getId()
							},
							callStack: {
								name: 'getDataItem',
								params: [this.getId()]
							}
						},
						actions: {
							// This action is currently not exposed as a dataItem API . Will only be exposed when needed
							// setLabel: {
							// 	eventName:'label',
							// 	info:{
							// 		refresh: { render: true }
							// 	},
							// 	getUndoActions: () => [{ params:[this.dataItemModel.itemLabel] }]
							// },
							setAggregation: {
								eventName: 'aggregation',
								getUndoActions: function getUndoActions() {
									return [{ params: [_this.hasDefaultAggregation() ? undefined : _this.getAggregation()] }];
								},
								autoCreateTransaction: true,
								transactionParamIndex: 1,
								transactionAPI: this.transaction
							},
							setFormat: {
								eventName: 'format',
								info: {
									refresh: { data: true /* TODO: livewidget_cleanup - should not refresh data, but for some reason the data format change is not rendered properly without data refresh*/
									} },
								getUndoActions: function getUndoActions() {
									return [{ params: [_this.hasDefaultFormat() ? undefined : _this.getFormat()] }];
								}
							},
							setSort: {
								eventName: 'sort',
								transactionParamIndex: 1,
								getUndoActions: function getUndoActions() {
									return [{ params: [_this.hasDefaultSort() ? undefined : _this.getSort()] }];
								}
							},
							setTopBottom: {
								eventName: 'topbottom',
								getUndoActions: function getUndoActions() {
									return [{ params: [_this.getTopBottom()] }];
								},
								autoCreateTransaction: true,
								transactionParamIndex: 1,
								transactionAPI: this.transaction
							},
							setBinning: {
								eventName: 'binning',
								getUndoActions: function getUndoActions() {
									return [{ params: [_this.getBinning()] }];
								},
								autoCreateTransaction: true,
								transactionParamIndex: 1,
								transactionAPI: this.transaction
							},
							drillUp: {
								eventName: 'drillUp',
								getUndoActions: drillGetUndoActions,
								autoCreateTransaction: true,
								transactionParamIndex: 1,
								transactionAPI: this.transaction
							},
							drillDown: {
								eventName: 'drillDown',
								getUndoActions: drillGetUndoActions,
								autoCreateTransaction: true,
								transactionParamIndex: 1,
								transactionAPI: this.transaction
							},
							clearDrill: {
								eventName: 'clearDrill',
								getUndoActions: drillGetUndoActions,
								autoCreateTransaction: true,
								transactionParamIndex: 0,
								transactionAPI: this.transaction
							}
						}
					}

				};
			}
			return this.apiSpec;
		};

		return APISpec;
	}();

	return APISpec;
});
//# sourceMappingURL=DataItemAPISpec.js.map