using System;
using System.Collections.Generic;
using log4net;
using Quadarax.Foundation.Infrastructure.Layers;

namespace Quadarax.Foundation.Infrastructure
{
    public static class Infra
    {

        private static ILog _logger = LogManager.GetLogger(typeof(Infra));

        public static bool IsInitialized { get; private set; }

        public static void Initialize<TGlobalLayer>(string globalLayerName,params object[] initialArgs) where TGlobalLayer : GlobalLayer
        {
            if (IsInitialized)
                throw new InvalidOperationException("Infrastructure is already initialized!");

            GlobalContainer.Instance.CreateGlobal<TGlobalLayer>(globalLayerName);
            IsInitialized = true;
        }

        public static TModule Get<TModule>() where TModule : IModule
        {
            if (!IsInitialized)
                throw new InvalidOperationException("Infrastructure is not initialized! Call Infra.Initialize first!");
            return GlobalContainer.Instance.RootLayer.Get<TModule>();
        }

        public static IEnumerable<string> GetLayerNames()
        {
            return GlobalContainer.Instance.GetLayerNames();
        }

        public static string Dump()
        {
            if (!IsInitialized)
                return "Not initialized!";
            return GlobalContainer.Instance.Dump();
        }

        public static string DumpContainers()
        {
            if (!IsInitialized)
                return "Not initialized!";
            return GlobalContainer.Instance.DumpContainer();
        }

    }
}
