"""Warehouse feature stores + the store factory.

`get_feature_store(settings)` selects the backend from `settings.feature_store` (env `FXHNT_FEATURE_STORE`):
the default `"postgres"` returns the networked `TimescaleFeatureStore` over the operational DSN (the live
stack); the explicit opt-in `"duckdb"` returns the embedded `DuckDbFeatureStore` (used by tests + the B3
backtest). Phase 1 only adds the store + factory; the 19 direct instantiations are NOT yet migrated (that is
Phase 3)."""
from __future__ import annotations

from typing import TYPE_CHECKING

from fxhnt.adapters.warehouse.duckdb_feature_store import DuckDbFeatureStore
from fxhnt.adapters.warehouse.timescale_feature_store import TimescaleFeatureStore

if TYPE_CHECKING:
    from fxhnt.config import Settings
    from fxhnt.ports.warehouse import FeatureStore

__all__ = ["DuckDbFeatureStore", "TimescaleFeatureStore", "get_feature_store"]


def get_feature_store(settings: "Settings") -> "FeatureStore":
    """Return the feature store selected by `settings.feature_store` (default `"postgres"`; `"duckdb"`
    is the explicit opt-in for the embedded store)."""
    if settings.feature_store == "duckdb":
        return DuckDbFeatureStore(settings.warehouse_path)
    # `warehouse_table` (env FXHNT_WAREHOUSE_TABLE) selects WHICH table this store reads/writes — the
    # single knob that points the whole book/sim/edges stack at the legacy `features` table (default) or
    # Bybit `bybit_features`. Every get_feature_store consumer inherits it, so flipping the env runs all edges
    # on Bybit data with no per-site change. DuckDb path above is unaffected (single warehouse file).
    return TimescaleFeatureStore(settings.operational_dsn, table=settings.warehouse_table)
