namespace ZB.MOM.WW.MxGateway.Server.Security.Authentication;

public sealed record ApiKeyAdminParseResult(
    bool IsApiKeyCommand,
    ApiKeyAdminCommand? Command,
    string? Error)
{
    /// <summary>Returns a result indicating the input was not an API key command.</summary>
    /// <returns>A result with <see cref="IsApiKeyCommand"/> set to <see langword="false"/>.</returns>
    public static ApiKeyAdminParseResult NotApiKeyCommand()
    {
        return new ApiKeyAdminParseResult(false, null, null);
    }

    /// <summary>Returns a successful parse result with the parsed API key command.</summary>
    /// <param name="command">Parsed API key administration command.</param>
    /// <returns>A successful <see cref="ApiKeyAdminParseResult"/> wrapping <paramref name="command"/>.</returns>
    public static ApiKeyAdminParseResult Success(ApiKeyAdminCommand command)
    {
        return new ApiKeyAdminParseResult(true, command, null);
    }

    /// <summary>Returns a parse result with the specified error message.</summary>
    /// <param name="error">Error message describing the parse failure.</param>
    /// <returns>A failed <see cref="ApiKeyAdminParseResult"/> carrying <paramref name="error"/>.</returns>
    public static ApiKeyAdminParseResult Fail(string error)
    {
        return new ApiKeyAdminParseResult(true, null, error);
    }
}
