/*
 * fruity
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 0.0.1
 * Generated by: https://github.com/openapitools/openapi-generator.git
 */

#nullable enable

using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Api;

namespace Org.OpenAPITools.Extensions
{
    /// <summary>
    /// Extension methods for IHostBuilder
    /// </summary>
    public static class IHostBuilderExtensions
    {
        /// <summary>
        /// Add the api to your host builder.
        /// </summary>
        /// <param name="builder"></param>
        public static IHostBuilder ConfigureApi<TDefaultApi>(this IHostBuilder builder)
            where TDefaultApi : class, IApi.IDefaultApi
        {
            builder.ConfigureServices((context, services) => 
            {
                HostConfiguration<TDefaultApi> config = new HostConfiguration<TDefaultApi>(services);

                IServiceCollectionExtensions.AddApi(services, config);
            });

            return builder;
        }

        /// <summary>
        /// Add the api to your host builder.
        /// </summary>
        /// <param name="builder"></param>
        public static IHostBuilder ConfigureApi(this IHostBuilder builder)
            => ConfigureApi<DefaultApi>(builder);

        /// <summary>
        /// Add the api to your host builder.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="options"></param>
        public static IHostBuilder ConfigureApi<TDefaultApi>(this IHostBuilder builder, Action<HostBuilderContext, IServiceCollection, HostConfiguration<TDefaultApi>> options)
            where TDefaultApi : class, IApi.IDefaultApi
        {
            builder.ConfigureServices((context, services) => 
            {
                HostConfiguration<TDefaultApi> config = new HostConfiguration<TDefaultApi>(services);

                options(context, services, config);

                IServiceCollectionExtensions.AddApi(services, config);
            });

            return builder;
        }

        /// <summary>
        /// Add the api to your host builder.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="options"></param>
        public static IHostBuilder ConfigureApi(this IHostBuilder builder, Action<HostBuilderContext, IServiceCollection, HostConfiguration<DefaultApi>> options)
            => ConfigureApi<DefaultApi>(builder, options);
    }
}
