from typing import TypedDict

from backends.editor.utils.webapp_config import webapp_config


class ConfiguredDatasets(TypedDict):
    nodes_datasets: list[str]
    edges_datasets: list[str]


def get_source_datasets_config() -> ConfiguredDatasets:
    available_node_datasets = webapp_config.nodes_datasets
    available_edge_datasets = webapp_config.edges_datasets

    if not available_node_datasets or not available_edge_datasets:
        all_project_dataset_names: list[str] = [
            ds.name for ds in webapp_config.default_project.list_datasets(as_type="listitems")
        ]

        if not available_node_datasets:
            available_node_datasets = all_project_dataset_names

        if not available_edge_datasets:
            available_edge_datasets = all_project_dataset_names

    return {"nodes_datasets": available_node_datasets, "edges_datasets": available_edge_datasets}
