from __future__ import annotations

from pydantic import BaseModel

from graph.connections.db_handler import DbHandler
from solutions.graph.models import GraphId
from stores.graph_metadata_snapshot_store import GraphMetadataSnapshotStore
from stores.graph_metadata_store import GraphMetadataStore


class Params(BaseModel):
    graph_id: GraphId


def delete_graph(
    store: GraphMetadataStore, snapshot_store: GraphMetadataSnapshotStore | None, db_handler: DbHandler, params: Params
) -> None:
    """
    Raises:
        GraphDoesNotExistError
        GraphMetadataStoreError
    """
    graph_id = params.graph_id
    try:
        store.delete(graph_id)
        if snapshot_store:
            snapshot_store.delete_all(graph_id)
    finally:
        if db_handler.db_exists():
            db_handler.delete_db()
