"use strict";

exports.__esModule = true;
exports.getContribute = getContribute;
exports.getContributeType = getContributeType;
exports.getRouteData = getRouteData;

var _core = require("@selfcommunity/core");

/**
 * From obj extract type of the contribution
 * @param obj
 */
function getContributeType(obj) {
  return _core.SCFeedObjectTypologyType.DISCUSSION in obj ? _core.SCFeedObjectTypologyType.DISCUSSION : _core.SCFeedObjectTypologyType.POST in obj ? _core.SCFeedObjectTypologyType.POST : _core.SCFeedObjectTypologyType.STATUS in obj ? _core.SCFeedObjectTypologyType.STATUS : _core.SCCommentTypologyType in obj ? _core.SCCommentTypologyType : null;
}
/**
 * From obj extract the contribution
 * @param obj
 */


function getContribute(obj) {
  return _core.SCFeedObjectTypologyType.DISCUSSION in obj ? obj[_core.SCFeedObjectTypologyType.DISCUSSION] : _core.SCFeedObjectTypologyType.POST in obj ? obj[_core.SCFeedObjectTypologyType.POST] : _core.SCFeedObjectTypologyType.STATUS in obj ? obj[_core.SCFeedObjectTypologyType.STATUS] : _core.SCCommentTypologyType in obj ? obj[_core.SCCommentTypologyType] : null;
}
/**
 * Get data for scRoutingContext.url()
 * @param obj (Discussion, Post, Status, Comment)
 */


function getRouteData(obj) {
  let data = {};

  if (obj.type === _core.SCFeedObjectTypologyType.DISCUSSION || obj.type === _core.SCFeedObjectTypologyType.POST || obj.type === _core.SCFeedObjectTypologyType.STATUS) {
    data = obj;
  } else if (obj.type === _core.SCCommentTypologyType) {
    const contribution_type = getContributeType(obj);
    data = Object.assign({}, obj, {
      contribution_type: contribution_type,
      contribution_id: obj[contribution_type]
    });
  }

  return data;
}