"""Benchmark configuration — DSNs, Docker tags, scale presets."""

from __future__ import annotations

import os
from dataclasses import dataclass

# ---------------------------------------------------------------------------
# Database connection settings
# ---------------------------------------------------------------------------

AGE_DSN = os.environ.get(
    "BENCH_AGE_DSN",
    "host=/var/run/postgresql port=5433 dbname=piggie user=gregf",
)
AGE_GRAPH = os.environ.get("BENCH_AGE_GRAPH", "bench")

NEO4J_URI = os.environ.get("BENCH_NEO4J_URI", "bolt://localhost:7687")
NEO4J_USER = os.environ.get("BENCH_NEO4J_USER", "neo4j")
NEO4J_PASSWORD = os.environ.get("BENCH_NEO4J_PASSWORD", "benchpass123")

KUZU_DB_PATH = os.environ.get("BENCH_KUZU_PATH", "/tmp/kuzu_bench")

NEBULA_HOST = os.environ.get("BENCH_NEBULA_HOST", "localhost")
NEBULA_PORT = int(os.environ.get("BENCH_NEBULA_PORT", "9669"))
NEBULA_USER = os.environ.get("BENCH_NEBULA_USER", "root")
NEBULA_PASSWORD = os.environ.get("BENCH_NEBULA_PASSWORD", "nebula")
NEBULA_SPACE = os.environ.get("BENCH_NEBULA_SPACE", "bench")

# Docker image tags
NEO4J_IMAGE = "neo4j:5-community"
NEBULA_METAD_IMAGE = "vesoft/nebula-metad:v3.8.0"
NEBULA_GRAPHD_IMAGE = "vesoft/nebula-graphd:v3.8.0"
NEBULA_STORAGED_IMAGE = "vesoft/nebula-storaged:v3.8.0"

# ---------------------------------------------------------------------------
# Scale presets
# ---------------------------------------------------------------------------

@dataclass(frozen=True)
class ScalePreset:
    """Defines a benchmark scale level."""

    name: str
    num_nodes: int
    num_edges: int
    vec_dims: int
    seed: int = 42


SCALES: dict[str, ScalePreset] = {
    "10k": ScalePreset(name="10k", num_nodes=10_000, num_edges=50_000, vec_dims=128),
    "100k": ScalePreset(name="100k", num_nodes=100_000, num_edges=500_000, vec_dims=128),
    "1m": ScalePreset(name="1m", num_nodes=1_000_000, num_edges=5_000_000, vec_dims=128),
}

DEFAULT_SCALE = "10k"

# ---------------------------------------------------------------------------
# Measurement settings
# ---------------------------------------------------------------------------

WARMUP_ITERATIONS = 3
MEASURED_ITERATIONS = 10

# All supported database keys
ALL_DBS = ("age", "neo4j", "kuzu", "nebula")

# ---------------------------------------------------------------------------
# Algorithm benchmark settings
# ---------------------------------------------------------------------------

ALGO_SCALE_CONFIG: dict[str, dict[str, int]] = {
    "10k":  {"warmup": 3, "iterations": 10},
    "100k": {"warmup": 2, "iterations": 5},
    "1m":   {"warmup": 1, "iterations": 3},
}

ALGO_SCALE_SKIP: dict[str, set[str]] = {
    "1m": {
        "C02_betweenness", "C03_closeness", "C04_eigenvector",
        "P03_all_shortest_paths", "M03_greedy_modularity", "E01_node2vec",
    },
}

ALGO_FAMILIES = (
    "centrality", "community", "paths", "ranking",
    "similarity", "link_prediction", "embeddings",
)

# Competitor target times (ms) — populated after running neo4j benchmarks.
# Used by the scorecard to track optimization progress.
ALGO_TARGETS: dict[str, float] = {}

# All workload IDs
ALL_WORKLOADS = (
    "W01_node_creation",
    "W02_edge_creation",
    "W03_point_lookup",
    "W04_pattern_match",
    "W05_aggregation",
    "W06_vle",
    "W07_shortest_path",
    "W08_pagerank",
    "W09_vector_search",
    "W10_hybrid_search",
    "W11_bulk_load",
    "W12_concurrent",
)
