// <auto-generated />

#pragma warning disable

using Microsoft.CodeAnalysis;

namespace Polyfills;

[Embedded]
internal static class Ensure
{
    public static void NotEmpty<T>(IEnumerable<T> value, [CallerArgumentExpression(nameof(value))] string name = "")
    {
        const string ArgumentCannotBeEmptyMsg = "Argument cannot be empty.";

        if (value is null)
        {
            return;
        }
        else if (value is ICollection<T> { Count: 0 })
        {
            throw new ArgumentException(ArgumentCannotBeEmptyMsg, name);
        }
        else if (value is ICollection { Count: 0 })
        {
            throw new ArgumentException(ArgumentCannotBeEmptyMsg, name);
        }
        else if (value is IReadOnlyCollection<T> { Count: 0 })
        {
            throw new ArgumentException(ArgumentCannotBeEmptyMsg, name);
        }
        else if (value is T[] { Length: 0 })
        {
            throw new ArgumentException(ArgumentCannotBeEmptyMsg, name);
        }
        else if (!value.Any())
        {
            throw new ArgumentException(ArgumentCannotBeEmptyMsg, name);
        }
    }

    public static string NotNullOrWhiteSpace([NotNull] string value, [CallerArgumentExpression(nameof(value))] string name = "")
    {
        if (value is null)
        {
            throw new ArgumentNullException(name);
        }
        else if (string.IsNullOrWhiteSpace(value))
        {
            throw new ArgumentException("Argument cannot be whitespace.", name);
        }

        return value;
    }

    public static void NotEmpty(string value, [CallerArgumentExpression(nameof(value))] string name = "")
    {
        if (value?.Length == 0)
        {
            throw new ArgumentException("Argument cannot be empty.", name);
        }
    }
}
