using Microsoft.OpenApi.Models;
using System.Reflection;

namespace VentaUniformesapi
{
    //clase de inyeccion de depèndencias
    public static  class DependencyInjectionService
    {
        public static IServiceCollection AddWebApi(this IServiceCollection services)
        {
            services.AddSwaggerGen(option =>
            {
                option.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version = "v1",
                    Title = "VentaUniformesapi",
                    Description = "Plantilla generica para apis"
                });
                //parametros de seguridad-----------------------------------
                option.AddSecurityDefinition("Beare", new OpenApiSecurityScheme
                {
                    In = ParameterLocation.Header,
                    Description="Ingrese un tokenVálido",
                    Name="Authorization",
                    Type=SecuritySchemeType.Http,
                    BearerFormat="JWT",
                    Scheme="Bearer"
                });
                option.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference=new OpenApiReference
                            {
                                Type=ReferenceType.SecurityScheme,
                                Id="Bearer"
                            }

                        },
                        new string[]{ }
                    }
                });
                //-----------------------------------------------------------
                var fileName = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                option.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, fileName));
            });
            return services;
        }
    }
}
