using HRD.AppLogger;
using HRD.LDAPService;
using HRD.LDAPService.JWT;
using HRD.WebApi;
using Microsoft.Extensions.Configuration;

namespace XUnitWebApi.SharedConfig
{
    public static class Shared_Test_Config
    {
        public static void Init_Webapi_Context()
        {
            if (WebApiConfig.Connectionstring != default) return; //all test are running simultain using the same WebApiConfig, therefore it must be initialised only one time
            var app_path = Directory.GetCurrentDirectory();
            var pos = app_path.IndexOf("XUnitDAL.Test");
            if (pos >= 0) app_path = app_path.Remove(pos);
            app_path += "StaffDBServer\\appsettings.json";

            IConfiguration configuration = new ConfigurationBuilder().AddJsonFile(app_path, true, true).Build();
            WebApiConfig.Init(configuration);

            WebApiConfig.AssemblyName = "KabionlineServer_test";
            WebApiConfig.AssemblyVersion = "xxx.xx";
            //WebApiConfig.Connectionstring = Config_ConnectionString;
            //WebApiConfig.NlogConnectionstring = Config_ConnectionString;
            WebApiConfig.NlogDBLogLevel = EN_LoggingLevel.Error;
            WebApiConfig.NlogFileLogLevel = EN_LoggingLevel.Off;
            WebApiConfig.RaiseRepositoryExceptions = false;

            //JWT#1
            var jwtRoleList = new List<JwtRole>();
            var ADGroupPrefix = WebApiConfig.IsLive ? "" : "__Test";
            //jwtRoleList.Add(new JwtRole(JwtGlobals.ROLE_USER, "GG_WebApp" + ADGroupPrefix + "_Kabionline_User")); //(RO) nur eigene
            //jwtRoleList.Add(new JwtRole(JwtGlobals.ROLE_MASTER, "GG_WebApp" + ADGroupPrefix + "_Kabionline_Master")); //RW ALLE Abteilungen
            //jwtRoleList.Add(new JwtRole(JwtGlobals.ROLE_DEPARTMENTUSER, "GG_WebApp" + ADGroupPrefix + "_Kabionline_DepartmentUser")); //(RW) auch andere aus eigener Abteilung
            //jwtRoleList.Add(new JwtRole(JwtGlobals.ROLE_DEPARTMENTMASTER, "GG_WebApp" + ADGroupPrefix + "_Kabionline_DepartmentMaster")); //(RW) auch andere aus eigener Abteilung

            JwtTokenConfig.JwtRoleList = jwtRoleList;
        }
    }
}