using Diligent.WebAPI.Host.Middlewares;
using Microsoft.AspNetCore.Mvc;

namespace Diligent.WebAPI.Host.Extensions
{
    public static class ModelValidationMIddlewareConfiguration
    {
        public static void ConfigureValidationMiddleware(this WebApplicationBuilder builder)
        {
            var services = builder.Services;
            // Override default model validation middleware.
            services.Configure<ApiBehaviorOptions>(options =>
            {
                options.SuppressModelStateInvalidFilter = true;
            });

            // Register custom validation middleware
            services.AddMvcCore(options =>
            {
                options.Filters.Add(typeof(ModelValidationMiddleware));
            })
            .AddDataAnnotations();
        }
    }
}
