<commit_before>﻿using System;
using System.Collections.Generic;
using System.Globalization;

namespace Tgstation.Server.Api.Rights
{
	/// <summary>
	/// Helper for <see cref="RightsType"/>s
	/// </summary>
	public static class RightsHelper
	{
		/// <summary>
		/// Map of <see cref="RightsType"/>s to their respective flag <see cref="Enum"/>s
		/// </summary>
		static readonly IReadOnlyDictionary<RightsType, Type> TypeMap = new Dictionary<RightsType, Type>
		{
			{ RightsType.Administration, typeof(AdministrationRights) },
			{ RightsType.InstanceManager, typeof(InstanceManagerRights) },
			{ RightsType.Repository, typeof(RepositoryRights) },
			{ RightsType.Byond, typeof(ByondRights) },
			{ RightsType.DreamMaker, typeof(DreamMakerRights) },
			{ RightsType.DreamDaemon, typeof(DreamDaemonRights) },
			{ RightsType.ChatBots, typeof(ChatBotRights) },
			{ RightsType.Configuration, typeof(ConfigurationRights) },
			{ RightsType.InstanceUser, typeof(InstanceUserRights) }
		};

		/// <summary>
		/// Map a given <paramref name="rightsType"/> to its respective <see cref="Enum"/> <see cref="Type"/>
		/// </summary>
		/// <param name="rightsType">The <see cref="RightsType"/> to lookup</param>
		/// <returns>The <see cref="Enum"/> <see cref="Type"/> of the given <paramref name="rightsType"/></returns>
		public static Type RightToType(RightsType rightsType) => TypeMap[rightsType];

		/// <summary>
		/// Gets the role claim name used for a given <paramref name="right"/>
		/// </summary>
		/// <typeparam name="TRight">The <see cref="RightsType"/></typeparam>
		/// <param name="right">The <typeparamref name="TRight"/></param>
		/// <returns>A <see cref="string"/> representing the claim role name</returns>
		public static string RoleNames<TRight>(TRight right) where TRight : Enum
		{
			var flags = new List<string>();
			IEnumerable<string> GetRoleNames()
			{
				foreach (Enum J in Enum.GetValues(right.GetType()))
					if (Convert.ToInt32(J, CultureInfo.InvariantCulture) != 0 && right.HasFlag(J))
						yield return String.Concat(typeof(TRight).Name, '.', J.ToString());
			}

			var names = GetRoleNames();
			return String.Join(",", names);
		}

		/// <summary>
		/// Gets the role claim name used for a given <paramref name="rightsType"/> and <paramref name="right"/>
		/// </summary>
		/// <param name="rightsType">The <see cref="RightsType"/></param>
		/// <param name="right">The right value</param>
		/// <returns>A <see cref="string"/> representing the claim role name</returns>
		public static string RoleName(RightsType rightsType, Enum right)
		{
			var enumType = TypeMap[rightsType];<commit_msg>Make RightsHelper use its own helper<commit_after>﻿using System;
using System.Collections.Generic;
using System.Globalization;

namespace Tgstation.Server.Api.Rights
{
	/// <summary>
	/// Helper for <see cref="RightsType"/>s
	/// </summary>
	public static class RightsHelper
	{
		/// <summary>
		/// Map of <see cref="RightsType"/>s to their respective flag <see cref="Enum"/>s
		/// </summary>
		static readonly IReadOnlyDictionary<RightsType, Type> TypeMap = new Dictionary<RightsType, Type>
		{
			{ RightsType.Administration, typeof(AdministrationRights) },
			{ RightsType.InstanceManager, typeof(InstanceManagerRights) },
			{ RightsType.Repository, typeof(RepositoryRights) },
			{ RightsType.Byond, typeof(ByondRights) },
			{ RightsType.DreamMaker, typeof(DreamMakerRights) },
			{ RightsType.DreamDaemon, typeof(DreamDaemonRights) },
			{ RightsType.ChatBots, typeof(ChatBotRights) },
			{ RightsType.Configuration, typeof(ConfigurationRights) },
			{ RightsType.InstanceUser, typeof(InstanceUserRights) }
		};

		/// <summary>
		/// Map a given <paramref name="rightsType"/> to its respective <see cref="Enum"/> <see cref="Type"/>
		/// </summary>
		/// <param name="rightsType">The <see cref="RightsType"/> to lookup</param>
		/// <returns>The <see cref="Enum"/> <see cref="Type"/> of the given <paramref name="rightsType"/></returns>
		public static Type RightToType(RightsType rightsType) => TypeMap[rightsType];

		/// <summary>
		/// Gets the role claim name used for a given <paramref name="right"/>
		/// </summary>
		/// <typeparam name="TRight">The <see cref="RightsType"/></typeparam>
		/// <param name="right">The <typeparamref name="TRight"/></param>
		/// <returns>A <see cref="string"/> representing the claim role name</returns>
		public static string RoleNames<TRight>(TRight right) where TRight : Enum
		{
			var flags = new List<string>();
			IEnumerable<string> GetRoleNames()
			{
				foreach (Enum J in Enum.GetValues(right.GetType()))
					if (Convert.ToInt32(J, CultureInfo.InvariantCulture) != 0 && right.HasFlag(J))
						yield return String.Concat(typeof(TRight).Name, '.', J.ToString());
			}

			var names = GetRoleNames();
			return String.Join(",", names);
		}

		/// <summary>
		/// Gets the role claim name used for a given <paramref name="rightsType"/> and <paramref name="right"/>
		/// </summary>
		/// <param name="rightsType">The <see cref="RightsType"/></param>
		/// <param name="right">The right value</param>
		/// <returns>A <see cref="string"/> representing the claim role name</returns>
		public static string RoleName(RightsType rightsType, Enum right)
		{
			var enumType = RightToType(rightsType);
{'fraction_non_alphanumeric': 0.16165057732349045, 'fraction_numerical': 0.001135718341851221, 'mean_word_length': 4.1400778210116735, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5036891', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1597, 'n_words': 398}