mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-04-28 10:15:47 +02:00
30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
using System.Collections.Immutable;
|
|
|
|
namespace Phantom.Server.Services.Users;
|
|
|
|
public abstract record AddUserError {
|
|
private AddUserError() {}
|
|
|
|
public sealed record NameIsEmpty : AddUserError;
|
|
|
|
public sealed record NameIsTooLong(int MaximumLength) : AddUserError;
|
|
|
|
public sealed record NameAlreadyExists : AddUserError;
|
|
|
|
public sealed record PasswordIsInvalid(ImmutableArray<PasswordRequirementViolation> Violations) : AddUserError;
|
|
|
|
public sealed record UnknownError : AddUserError;
|
|
}
|
|
|
|
public static class AddUserErrorExtensions {
|
|
public static string ToSentences(this AddUserError error, string delimiter) {
|
|
return error switch {
|
|
AddUserError.NameIsEmpty => "Name cannot be empty.",
|
|
AddUserError.NameIsTooLong e => "Name cannot be longer than " + e.MaximumLength + " character(s).",
|
|
AddUserError.NameAlreadyExists => "Name is already occupied.",
|
|
AddUserError.PasswordIsInvalid e => string.Join(delimiter, e.Violations.Select(static v => v.ToSentence())),
|
|
_ => "Unknown error."
|
|
};
|
|
}
|
|
}
|