// Copyright Epic Games, Inc. All Rights Reserved.
using System.ComponentModel;
using EpicGames.Core;
namespace EpicGames.Horde.Users
{
///
/// Identifier for a user
///
/// Id to construct from
[LogValueType]
[JsonSchemaString]
[TypeConverter(typeof(BinaryIdTypeConverter))]
[BinaryIdConverter(typeof(UserIdConverter))]
public readonly record struct UserId(BinaryId Id)
{
///
/// Constant value for empty user id
///
public static UserId Empty { get; } = default;
///
/// Special user id for an anonymous administrator
///
public static UserId Anonymous { get; } = UserId.Parse("63f7d3525119b9aa4c0f035a");
///
public static UserId Parse(string text) => new UserId(BinaryId.Parse(text));
///
public static bool TryParse(string text, out UserId id)
{
if (BinaryId.TryParse(text, out BinaryId objectId))
{
id = new UserId(objectId);
return true;
}
else
{
id = default;
return false;
}
}
///
public override readonly string ToString() => Id.ToString();
}
///
/// Converter to and from instances.
///
class UserIdConverter : BinaryIdConverter
{
///
public override UserId FromBinaryId(BinaryId id) => new UserId(id);
///
public override BinaryId ToBinaryId(UserId value) => value.Id;
}
}