import { get } from 'lodash';

const EDGE_ROLE = require('../constant/relationship/edge-role.constant');
const { EDGE, EDGE_TYPE } = require('../constant/relationship/label.constant');

module.exports.isFeatureSettingsEnabled = (user) => get(user, 'features.analytics.rollOut.value');

//  # TODO: modify after mongo => neptune migration
module.exports.isAnalyticsAdmin = ({ relationships }, isNeptune) =>
  (relationships &&
    isNeptune &&
    relationships.some(({ edge: { label, type } }) => type === EDGE_TYPE.ROLE && label === EDGE.ANALYTICS_ADMIN)) ||
  (relationships && relationships.some(({ role }) => role === EDGE_ROLE.ANALYTICS_ADMIN));
