import logging
from typing import Dict

from graph.connections.db_connection import DbConnection
from graph.ingestion.dataiku.data_types import DataikuDataType

logger = logging.getLogger(__name__)


def create_node_table(
    table_name: str, primary_key: str, property_to_type: Dict[str, DataikuDataType], connection: DbConnection
) -> None:
    from graph.connections.kuzu.db_connection import KuzuConnection
    from graph.connections.neo4j.db_connection import Neo4jConnection
    from graph.ingestion.kuzu.create_table import create_node_table as create_node_table_kuzu
    from graph.ingestion.neo4j.create_table import create_node_table as create_node_table_neo4j

    if isinstance(connection, KuzuConnection):
        create_node_table_kuzu(table_name, primary_key, property_to_type, connection)
    elif isinstance(connection, Neo4jConnection):
        create_node_table_neo4j(table_name, primary_key, property_to_type, connection)
    else:
        raise TypeError(f"Unsupported connection type: {type(connection)}")


def create_edge_table(
    table_name: str,
    from_node: str,
    to_node: str,
    property_to_type: Dict[str, DataikuDataType],
    connection: DbConnection,
) -> None:
    from graph.connections.kuzu.db_connection import KuzuConnection
    from graph.connections.neo4j.db_connection import Neo4jConnection
    from graph.ingestion.kuzu.create_table import create_edge_table as create_edge_table_kuzu
    from graph.ingestion.neo4j.create_table import create_edge_table as create_edge_table_neo4j

    if isinstance(connection, KuzuConnection):
        create_edge_table_kuzu(table_name, from_node, to_node, property_to_type, connection)
    elif isinstance(connection, Neo4jConnection):
        create_edge_table_neo4j(table_name, from_node, to_node, property_to_type, connection)
    else:
        raise TypeError(f"Unsupported connection type: {type(connection)}")
