#from dependency_injector import providers, containers

from Mapa_PU.model.baza_danych import Baza
from Mapa_PU.swdl.kontroler.swdl_helper import SwdlHelper
from Mapa_PU.swdl.kontroler.database_helper import DatabaseHelper
from Mapa_PU.swdl.kontroler.geometry_helper import GeometryHelper
from Mapa_PU.swdl.kontroler.forest_data_desc_helper import ForestDataDescHelper
from Mapa_PU.swdl.kontroler.swdl_object import SwdlCreator
from Mapa_PU.swdl.kontroler.swdl_converter import SwdlObjectConverter
from Mapa_PU.swdl.kontroler.header_converter import HeaderConverter
from Mapa_PU.swdl.kontroler.forest_data_set_converter import ForestDataSetConverter
from Mapa_PU.swdl.kontroler.forest_data_desc_converter import ForestDataDescConverter
from Mapa_PU.swdl.kontroler.forest_data_converter import ForestDataConverter
from Mapa_PU.swdl.kontroler.subarea_data_converter import SubareaDataConverter
from Mapa_PU.swdl.kontroler.forest_global_data_converter import ForestGlobalDataConverter
from Mapa_PU.swdl.kontroler.xml_converter import XmlConverter
from Mapa_PU.swdl.kontroler.swdl_helper_xml import SwdlHelperXml
from Mapa_PU.swdl.kontroler.data_export import DatabaseExport
from Mapa_PU.swdl.kontroler.forest_map_no_sf_helper import ForestMapNoSFHelper
from Mapa_PU.swdl.kontroler.forest_map_no_sf_converter import ForestMapNoSFConverter
from Mapa_PU.swdl.kontroler.forest_natural_values_helper import ForestNaturalValuesHelper
from Mapa_PU.swdl.kontroler.forest_natural_values_converter import ForestNaturalValuesConverter
from Mapa_PU.swdl.kontroler.database_controler import DatabaseControler


from Mapa_PU.swdl.containers.servicecontainer import ServiceContainer

class Container():
    """Singleton kontenera"""

    __instance=None

    Database=None
    Layers=None
    Version=None
    Root=None
    SwdlVersion=None

    @staticmethod
    def get():
        if Container.__instance==None:
            Container()
        return Container.__instance.scp
    def __init__(self):
        self.scp= ServiceContainer(
            DatabaseHelperInstance=lambda: DatabaseHelper(database=Container.Database),
            GeometryHelperInstance=lambda: GeometryHelper(),
            ForestDataDescHelperInstance=lambda: ForestDataDescHelper(self.scp.DatabaseHelperInstance),
            XmlConverterInstance=lambda : XmlConverter(),
            ForestNaturalValuesHelperInstance=lambda:ForestNaturalValuesHelper(self.scp.DatabaseHelperInstance),
            ForestMapNoSFHelperInstance=lambda: ForestMapNoSFHelper(self.scp.GeometryHelperInstance,Container.Layers),
            SwdlHelperInstance=lambda: SwdlHelper(self.scp.DatabaseHelperInstance,self.scp.GeometryHelperInstance,Container.Layers,self.scp.ForestDataDescHelperInstance,self.scp.ForestMapNoSFHelperInstance,self.scp.ForestNaturalValuesHelperInstance,Container.Root,Container.SwdlVersion),
            SwdlObjectConverterInstance=lambda: SwdlObjectConverter(HeaderConverter(),ForestDataSetConverter(ForestDataDescConverter(),ForestDataConverter(SubareaDataConverter()),ForestGlobalDataConverter(),ForestMapNoSFConverter(),ForestNaturalValuesConverter())),
            SwdlHelperXmlInstance=lambda: SwdlHelperXml(self.scp.XmlConverterInstance),
            SwdlCreatorInstance=lambda: SwdlCreator(self.scp.SwdlHelperInstance,self.scp.SwdlHelperXmlInstance,self.scp.XmlConverterInstance),
            DatabaseExportInstance=lambda: DatabaseExport(self.scp.DatabaseHelperInstance,Container.Layers,self.scp.GeometryHelperInstance),
            DatabaseControlerInstance=lambda:DatabaseControler(self.scp.DatabaseHelperInstance,Container.Version),
            ExcelInstance=lambda:Excel()
            )
        Container.__instance=self

# class Database(containers.DeclarativeContainer):
#     database=providers.Configuration('database')
#      
# class Layers(containers.DeclarativeContainer):
#     path=providers.Configuration('path')
#      
# class DatabaseHelperInstance(containers.DeclarativeContainer):
#     database_helper=providers.Singleton(DatabaseHelper,database=Database.database)
#      
# class GeometryHelperInstance(containers.DeclarativeContainer):
#     geometry_helper=providers.Singleton(GeometryHelper)
#      
# class ForestDataDescHelperInstance(containers.DeclarativeContainer):
#     forest_data_desc_helper=providers.Singleton(ForestDataDescHelper,DatabaseHelperInstance.database_helper)
#      
# class XmlConverterInstance(containers.DeclarativeContainer):
#     xml_converter=providers.Singleton(XmlConverter)
#      
# class SwdlHelperInstance(containers.DeclarativeContainer):
#     swdl_helper=providers.Singleton(SwdlHelper,DatabaseHelperInstance.database_helper,GeometryHelperInstance.geometry_helper,Layers.path,ForestDataDescHelperInstance.forest_data_desc_helper)
#      
# class SwdlObjectConverterInstance(containers.DeclarativeContainer):
#     swdl_object_converter=providers.Singleton(SwdlObjectConverter,providers.Singleton(HeaderConverter),providers.Singleton(ForestDataSetConverter,providers.Singleton(ForestDataDescConverter),providers.Singleton(ForestDataConverter,providers.Singleton(SubareaDataConverter)),providers.Singleton(ForestGlobalDataConverter)))
#  
# class SwdlHelperXmlInstance(containers.DeclarativeContainer):
#     swdl_helper_xml=providers.Singleton(SwdlHelperXml,XmlConverterInstance.xml_converter)
#      
# class SwdlCreatorInstance(containers.DeclarativeContainer):
#     swdl_creator=providers.Singleton(SwdlCreator,SwdlHelperInstance.swdl_helper,SwdlHelperXmlInstance.swdl_helper_xml,XmlConverterInstance.xml_converter)
#      
# class DatabaseExportInstance(containers.DeclarativeContainer):
#     database_export=providers.Singleton(DatabaseExport,DatabaseHelperInstance.database_helper,Layers.path,GeometryHelperInstance.geometry_helper)
#      
