{"size": 1278, "ext": "js", "max_stars_repo_path": "src/services/Project/GroupType/GroupType.js", "max_stars_repo_name": "Zverik/maproulette3", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/services/Project/GroupType/GroupType.js", "max_issues_repo_name": "Zverik/maproulette3", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/services/Project/GroupType/GroupType.js", "max_forks_repo_name": "Zverik/maproulette3", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.7209302326, "max_line_length": 71, "alphanum_fraction": 0.7644757433}
import _map from 'lodash/map'
import _fromPairs from 'lodash/fromPairs'
import _min from 'lodash/min'
import messages from './Messages'

// These constants are defined on the server
export const GROUP_TYPE_SUPERUSER = -1
export const GROUP_TYPE_ADMIN = 1
export const GROUP_TYPE_WRITE = 2
export const GROUP_TYPE_READ = 3

export const GroupType = Object.freeze({
  admin: GROUP_TYPE_ADMIN,
  write: GROUP_TYPE_WRITE,
  read: GROUP_TYPE_READ,
})

/**
 * Returns an object mapping group type values to raw internationalized
 * messages suitable for use with FormattedMessage or formatMessage.
 */
export const messagesByGroupType = _fromPairs(
  _map(messages, (message, key) => [GroupType[key], message])
)

/** Returns object containing localized labels  */
export const groupTypeLabels = intl => _fromPairs(
  _map(messages, (message, key) => [key, intl.formatMessage(message)])
)

/** Returns the most privileged of the given group types **/
export const mostPrivilegedGroupType = function(groupTypes) {
  return _min(groupTypes)
}

/**
 * Determines if the target group type is implied by the given list of
 * possessed group types.
 */
export const groupTypesImply = function(targetGroupType, groupTypes) {
  return mostPrivilegedGroupType(groupTypes) <= targetGroupType
}
