using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace HRD.WebApi.DAL.Middleware
{
    public static class WebApiMiddlewareExtensions
    {
        public static IApplicationBuilder UseDALMiddleware(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<WebApiMiddleware>();
        }

        public static void ConfigureDAL(this IServiceCollection services, WebApiMiddlewareOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            SetOptions(options);
        }

        private static void SetOptions(WebApiMiddlewareOptions options)
        {
            WebApiConfig.AssemblyVersion = options.AssemblyVersion;
            WebApiConfig.AssemblyName = options.AssemblyName;
            WebApiConfig.ClientVersion = options.ClientVersion;
            WebApiConfig.Connectionstring = options.Connectionstring;
            WebApiConfig.NlogConnectionstring = options.NlogConnectionstring;
            WebApiConfig.NlogDBLogLevel = options.NlogDBLogLevel;
            WebApiConfig.NlogFileLogLevel = options.NlogFileLogLevel;
            WebApiConfig.NlogLogDirectory = options.NlogLogDirectory;
        }
    }
}