from pathlib import Path
import os

from .constants import ENGINE_DUCKDB, DEFAULT_LOG_LEVEL


# Base Paths
# Root directory for all OCF data
OCF_HOME = Path(
    os.environ.get("OCF_HOME", Path.home() / ".ocf")
).expanduser()

DATA_DIR = OCF_HOME / "data"
CACHE_DIR = OCF_HOME / "cache"
LOG_DIR = OCF_HOME / "logs"

# Ensure paths exist (safe side effect)
for _dir in (DATA_DIR, CACHE_DIR, LOG_DIR):
    _dir.mkdir(parents=True, exist_ok=True)


# Storage Settings
DEFAULT_ENGINE = os.environ.get("OCF_ENGINE", ENGINE_DUCKDB)

DUCKDB_FILENAME = "ocf.duckdb"
DUCKDB_PATH = DATA_DIR / DUCKDB_FILENAME


# Date Defaults
DEFAULT_START_DATE = "2010-01-01"
DEFAULT_END_DATE = None  # Interpreted as "today" at runtime


# Performance & Execution
# Parallelism (used by CLI / orchestration layer)
MAX_WORKERS = int(os.environ.get("OCF_MAX_WORKERS", 4))

# Caching
ENABLE_CACHE = True
CACHE_EXPIRY_DAYS = 7


# Logging
LOG_LEVEL = os.environ.get("OCF_LOG_LEVEL", DEFAULT_LOG_LEVEL)
LOG_TO_FILE = True
LOG_TO_STDOUT = True
