'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _elementInstancesLayoutsManager = require('../managers/elementInstancesLayoutsManager');

var _elementInstancesLayoutsManager2 = _interopRequireDefault(_elementInstancesLayoutsManager);

var _appUtils = require('../utils/appUtils');

var _appUtils2 = _interopRequireDefault(_appUtils);

var _underscore = require('underscore');

var _underscore2 = _interopRequireDefault(_underscore);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var createElementInstanceLayout = function createElementInstanceLayout(props, params, callback) {
  _elementInstancesLayoutsManager2.default.create(props.data).then(_appUtils2.default.onCreate.bind(null, params, props.setProperty, 'Unable to create Element Instance Layout object.', callback));
}; /*
    * *******************************************************************************
    *  * Copyright (c) 2018 Edgeworx, Inc.
    *  *
    *  * This program and the accompanying materials are made available under the
    *  * terms of the Eclipse Public License v. 2.0 which is available at
    *  * http://www.eclipse.org/legal/epl-2.0
    *  *
    *  * SPDX-License-Identifier: EPL-2.0
    *  *******************************************************************************
    *
    */

var findElementInstancesLayoutsByUuid = function findElementInstancesLayoutsByUuid(props, params, callback) {
  var elementInstance = _appUtils2.default.getProperty(params, props.elementInstance);

  _elementInstancesLayoutsManager2.default.findByUuIds(elementInstance).then(_appUtils2.default.onFindOptional.bind(null, params, props.setProperty, callback));
};

var findElementInstancesLayoutsByUuids = function findElementInstancesLayoutsByUuids(props, params, callback) {
  var elementInstanceData = _appUtils2.default.getProperty(params, props.elementInstanceData);

  _elementInstancesLayoutsManager2.default.findByUuIds(_underscore2.default.pluck(elementInstanceData, props.field)).then(_appUtils2.default.onFindOptional.bind(null, params, props.setProperty, callback));
};

var updateLayout = function updateLayout(props, params, callback) {
  var elementInstanceId = _appUtils2.default.getProperty(params, props.elementInstanceId);

  _elementInstancesLayoutsManager2.default.updateLayoutByElementInstanceId(elementInstanceId, props.updatedData).then(_appUtils2.default.onUpdate.bind(null, params, 'Unable to update Element Insatnce Layout', callback));
};

var deleteElementInstancesLayoutsByUuids = function deleteElementInstancesLayoutsByUuids(props, params, callback) {
  var elementInstanceData = _appUtils2.default.getProperty(params, props.elementInstanceData);

  _elementInstancesLayoutsManager2.default.deleteLayoutsByUuids(_underscore2.default.pluck(elementInstanceData, props.field)).then(_appUtils2.default.onDeleteOptional.bind(null, params, callback));
};

exports.default = {
  createElementInstanceLayout: createElementInstanceLayout,
  findElementInstancesLayoutsByUuid: findElementInstancesLayoutsByUuid,
  findElementInstancesLayoutsByUuids: findElementInstancesLayoutsByUuids,
  updateLayout: updateLayout,
  deleteElementInstancesLayoutsByUuids: deleteElementInstancesLayoutsByUuids
};