Code/SboxSuperuser/Core/Permissions/UserDefinition.cs

A permissions data type. Holds a validated Steam ID, the group names a user belongs to, and a snapshot of permission entries with their integer values. Constructed through defensive copies so the stored state can't be mutated by the caller.

using SboxSuperuser.Core.Identity;

namespace SboxSuperuser.Core.Permissions;

internal sealed class UserDefinition
{
	internal string SteamId { get; }
	internal IReadOnlyList<string> Groups { get; }
	internal IReadOnlyDictionary<string, int> Entries { get; }

	internal UserDefinition( string steamId, IEnumerable<string> groups,
		IEnumerable<KeyValuePair<string, int>> entries )
	{
		SteamId = SteamIdentity.Validate( steamId, nameof( steamId ) );
		Groups = PolicyEntries.Groups( groups );
		Entries = PolicyEntries.Snapshot( entries );
	}
}