"""Thin wrappers that turn config resolution errors into clean CLI exits."""
from __future__ import annotations

from typing import Optional

import typer

from acdc_aws_etl_pipeline import config


def load_cfg(path: Optional[str] = None) -> dict:
    return config.load_config(path)


def env_of(cfg: dict, env: str) -> config.EnvConfig:
    try:
        return config.resolve_env(cfg, env)
    except config.ConfigError as exc:
        typer.secho(str(exc), fg=typer.colors.RED, err=True)
        raise typer.Exit(1)


def study_of(cfg: dict, study: str, env: str) -> config.StudyConfig:
    try:
        return config.resolve_study(cfg, study, env)
    except config.ConfigError as exc:
        typer.secho(str(exc), fg=typer.colors.RED, err=True)
        raise typer.Exit(1)
