"""Threshold Calibration Framework for EB1-GNN Tiered Routing.

This package provides tools for optimizing tiered routing thresholds using
offline evaluation data. The framework supports:

- Multi-objective optimization (quality vs cost vs latency)
- Pareto frontier analysis for threshold selection
- Cross-validation for robust threshold estimation
- Grid search, random search, and Bayesian optimization strategies
- Budget-constrained optimization with MIP/OR-Tools support

Example:
    from embergraphrouter.calibration import (
        ThresholdCalibrator,
        OfflineDataset,
        CalibrationConfig,
    )

    # Load offline evaluation data
    dataset = OfflineDataset.from_csv("calibration_data.csv")

    # Configure calibration
    config = CalibrationConfig(
        optimization_target="balanced",  # quality, cost, latency, or balanced
        quality_weight=0.5,
        cost_weight=0.3,
        latency_weight=0.2,
    )

    # Run calibration
    calibrator = ThresholdCalibrator(config)
    result = calibrator.calibrate(dataset)

    # Get optimal thresholds
    print(result.optimal_thresholds)
    print(result.report())

Budget-Constrained Optimization:
    from embergraphrouter.calibration import BudgetOptimizer, load_budget_thresholds

    # Create optimizer from calibration data
    optimizer = BudgetOptimizer.from_calibration_data(dataset)

    # Find optimal thresholds for $2/1K query budget
    result = optimizer.optimize_for_budget(cost_budget_per_1k=2.0)
    print(f"Quality: {result.quality:.1%}, Thresholds: {result.thresholds}")

    # Save Pareto frontier for runtime use
    optimizer.save_optimization_cache("budget_cache.json")

    # At runtime, load optimal thresholds for budget
    thresholds = load_budget_thresholds("budget_cache.json", cost_budget_per_1k=2.0)
"""

from .config import CalibrationConfig, CostModel, LatencyModel
from .dataset import DatasetSplit, OfflineDataset
from .metrics import CalibrationMetrics, TierMetrics
from .optimizer import (
    CalibrationResult,
    ParetoFrontier,
    ThresholdCalibrator,
)
from .report import CalibrationReport
from .search import (
    BayesianSearch,
    GridSearch,
    RandomSearch,
    SearchStrategy,
    ThresholdCandidate,
)
from .budget_optimizer import (
    BudgetOptimizer,
    ParetoFrontier as BudgetParetoFrontier,
    QueryProfile,
    TierCosts,
    load_budget_thresholds,
)

__all__ = [
    # Main API
    "ThresholdCalibrator",
    "CalibrationResult",
    "CalibrationConfig",
    # Data
    "OfflineDataset",
    "DatasetSplit",
    # Metrics
    "CalibrationMetrics",
    "TierMetrics",
    # Optimization
    "ParetoFrontier",
    "ThresholdCandidate",
    # Search strategies
    "SearchStrategy",
    "GridSearch",
    "RandomSearch",
    "BayesianSearch",
    # Models
    "CostModel",
    "LatencyModel",
    # Reporting
    "CalibrationReport",
    # Budget optimization
    "BudgetOptimizer",
    "BudgetParetoFrontier",
    "QueryProfile",
    "TierCosts",
    "load_budget_thresholds",
]
