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

namespace PARR.API.Installers
{
    public static class SwaggerInstaller
    {
        public static void InstallSwaggerService(this IServiceCollection services, IConfiguration configuration)
        {
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            services.AddEndpointsApiExplorer();

            var version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "1.0.0";

            services.AddSwaggerGen(x =>
            {
                //TODO: 
                x.SwaggerDoc(
                    "v1",
                    new OpenApiInfo
                    {
                        Title = "PARR API",
                        Version = $"v{version}",
                        Description = "API for the project \"PARR DVGD\"",
                        Contact = new OpenApiContact { Email = "IVC_TrubnikovME@dvgd.rzd;IVC_KuznetsovMV@dvgd.rzd", Name = "Trubnikov M.E., Kuznetsov M.V." },
                        License = new OpenApiLicense { Name = "© PTK-DVGD Software LLC" }
                    });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                x.IncludeXmlComments(xmlPath);
            });
        }


        public static void InstallSwagger(this WebApplication app)
        {
            // Configure the HTTP request pipeline.
            //todo: оставили swagger для прода
            //if (app.Environment.IsDevelopment())
            //{
                app.UseSwagger();
                app.UseSwaggerUI();
            //}
        }
    }
}
