using System;
namespace Umbraco.Cms.Core.Trees
{
[AttributeUsage(AttributeTargets.Class)]
public sealed class SearchableTreeAttribute : Attribute
{
public const int DefaultSortOrder = 1000;
public string ServiceName { get; }
public string MethodName { get; }
public int SortOrder { get; }
///
/// This constructor will assume that the method name equals `format(searchResult, appAlias, treeAlias)`.
///
/// Name of the service.
public SearchableTreeAttribute(string serviceName)
: this(serviceName, string.Empty)
{ }
///
/// This constructor defines both the Angular service and method name to use.
///
/// Name of the service.
/// Name of the method.
public SearchableTreeAttribute(string serviceName, string methodName)
: this(serviceName, methodName, DefaultSortOrder)
{ }
///
/// This constructor defines both the Angular service and method name to use and explicitly defines a sort order for the results
///
/// Name of the service.
/// Name of the method.
/// The sort order.
/// serviceName
/// or
/// methodName
/// Value can't be empty or consist only of white-space characters. - serviceName
public SearchableTreeAttribute(string serviceName, string methodName, int sortOrder)
{
if (serviceName == null) throw new ArgumentNullException(nameof(serviceName));
if (string.IsNullOrWhiteSpace(serviceName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(serviceName));
ServiceName = serviceName;
MethodName = methodName ?? throw new ArgumentNullException(nameof(methodName));
SortOrder = sortOrder;
}
}
}