using System.Web.Http;
using WebActivatorEx;
using Swashbuckle.Application;
using System.Linq;
using System.Reflection;
using FactorySystemApi;
using FactorySystemApi.Controllers;

[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
namespace FactorySystemApi
{
    public class SwaggerConfig
    {
        public static void Register()
        {
            var thisAssembly = typeof(SwaggerConfig).Assembly;

            GlobalConfiguration.Configuration
                .EnableSwagger(c =>
                {
                    c.SingleApiVersion("v1", "配方协同接口文档");


                    c.OperationFilter<HttpAuthHeaderFilter>();

                    c.IncludeXmlComments(string.Format("{0}/bin/FactorySystemModel.xml", System.AppDomain.CurrentDomain.BaseDirectory));
                    c.IncludeXmlComments(string.Format("{0}/bin/FactorySystemApi.xml", System.AppDomain.CurrentDomain.BaseDirectory));
                    c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
                    c.CustomProvider((defaultProvider) => new SwaggerCacheProvider(defaultProvider, string.Format("{0}/bin/FactorySystemApi.XML",System.AppDomain.CurrentDomain.BaseDirectory)));
                    c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
                })
                .EnableSwaggerUi(c =>
                {
                    c.InjectJavaScript(Assembly.GetExecutingAssembly(), "FactorySystemApi.Scripts.swagger.js");
                });
        }
    }
    
}
