using Facility.AspNetCore;
using Facility.Core.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using OapApi.v1.Client;
using OapApi.v1.Client.Http;
using OrchardCore.Mvc.Core.Utilities;

namespace OapApi.v1
{
	public class Startup : OrchardCore.Modules.StartupBase
	{
		public override void ConfigureServices(IServiceCollection services)
		{
			services.AddScoped<IOapApiV1, OapApiV1>();

			services.AddScoped(sp =>
			{
				return new OapApiV1HttpHandler(
					sp.GetRequiredService<IOapApiV1>(),
					new ServiceHttpHandlerSettings
					{
						RootPath = "/oap/api/v1",
					});
			});
		}

		public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
		{
			builder.UseFacilityExceptionHandler();
			builder.UseFacilityHttpHandler<OapApiV1HttpHandler>();
		}
	}
}
