from __future__ import annotations
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
    pass

import os

import yaml


def load_yaml_config(config_path: str) -> dict[str, Any]:
    """
    Loads configuration from YAML file.

    Args:
        config_path: Path to the configuration file.

    Returns:
        dict[str, Any]: Configuration dictionary.

    Raises:
        FileNotFoundError: If the configuration file is not found.
        ValueError: If there is an error parsing the configuration file.

    Example:
        >>> load_yaml_config("config.yaml")
        {"key": "value"}
    """
    if not os.path.exists(config_path):
        raise FileNotFoundError(f"Configuration file not found: {config_path}")
    try:
        with open(config_path, "r") as file:
            return yaml.safe_load(file)
    except yaml.YAMLError as e:
        raise ValueError(f"Error parsing configuration file: {e}")
    except Exception as e:
        raise ValueError(f"Error loading configuration file: {e}")


def save_yaml_config(config: dict[str, Any], config_path: str) -> None:
    """
    Saves configuration to YAML file.

    Args:
        config: Configuration dictionary.
        config_path: Path to save the configuration file.

    Example:
        >>> save_yaml_config({"key": "value"}, "config.yaml")
    """
    with open(config_path, "w") as file:
        yaml.dump(config, file)
