#global imports
from db.repository import Repository
from db.table_repository import TableRepository
from db.use_case_repository import UseCaseRepository
from db.entities.layer_adapter import LayerAdapter
from db.entities.table import Table

from typing import List

class LayerAdapterService:

    _table_repository = TableRepository()
    _layer_repository = Repository()
    _use_case_repository = UseCaseRepository()
    
    @staticmethod
    def check_layer(layer: LayerAdapter):
        '''
        checks if the given layer has correct mappings regarding the schema of the use_case
        '''
        # TODO implement with tables
        # schema = LayerAdapterService._schema_repository.put(layer.use_case)
        # for p in layer.properties:
        #     if p not in schema.mappings:
        #         raise ValueError(f'{p} is not existent in the schema!')

    @staticmethod
    def add_complete(layer: LayerAdapter):
        '''
        Add a new layer to the DB. Attribute mappings and cluster attributes of the given layer
        are used. Before inserting, the layer gets checked for consistency with the schema.

        @params:
            layer - Required : layer object holding correct data
        '''
        LayerAdapterService.check_layer(layer)
        LayerAdapterService._layer_repository.add(layer)
    
    @staticmethod
    def delete_all_use_cases():
        # TODO
        LayerAdapterService._layer_repository.delete_all_use_cases()
        LayerAdapterService._table_repository.delete_all()
        LayerAdapterService._use_case_repository.delete_all()
   