using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Kimuser.Infrastructure.StartupRegisters
{
    public static class SwaggerRegister
    {
        public static void RegisterSwaggerServices(this IServiceCollection services)
        {
            services.AddSwaggerGen(c =>
            {

                c.SwaggerDoc("v1", new OpenApiInfo { Title = "API người dùng", Version = "v1" });

                //c.IncludeXmlComments("/swagger/v1/swagger.json", true);
                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name = "Authorization",
                    //In = "header",
                    //Type = "apiKey"
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement());

            });
        }

        /// <summary>
        /// Đăng ký Swagger App
        /// </summary>
        /// <param name="app"></param>
        public static void RegisterSwagger(this IApplicationBuilder app)
        {
            app.UseSwagger();

            //app.UseReDoc(c =>
            //{
            //    c.SpecUrl = "/swagger/v1/swagger.json";
            //    c.DocumentTitle = "API người dùng";
            //    c.RoutePrefix = string.Empty;
            //    c.HideDownloadButton();
            //    c.NativeScrollbars();
            //});

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "User API");
                c.RoutePrefix = string.Empty;
            });
        }
    }
}
