using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;

using Monitoring.Interfaces;

namespace Monitoring.Models.Binders;

public class TableSortModelBinderProvider : IModelBinderProvider
{
	public IModelBinder? GetBinder(ModelBinderProviderContext context)
	{
		ArgumentNullException.ThrowIfNull(context);

		return context.Metadata.ModelType == typeof(IEnumerable<ITableSort>)
			? new BinderTypeModelBinder(typeof(TableSortModelBinder))
			: (IModelBinder?)null;
	}
}