"""
Configuration loader module
"""

import os
from pathlib import Path
from typing import TypedDict

import yaml


config = {}

ROOT_PATH = Path(__file__).parent.parent.parent

CONFIG_PATH = os.path.join(ROOT_PATH.absolute(), "config.yaml")


class RemoteConfig(TypedDict):
    """Type definition for remote configuration."""

    host: str
    port: str
    verify_cert: bool
    client_key: str
    ca_cert: str
    ca_chain: str


def load_config():
    """
    Load and parse the YAML configuration file.

    Returns:
        dict: Configuration dictionary containing remote settings and forwards.
    """
    with open(CONFIG_PATH, "r") as f:
        config = yaml.safe_load(f)
        return config


def get_config():
    """
    Get the loaded configuration.

    Returns:
        dict: Configuration dictionary containing remote settings and forwards.
    """

    if not config:
        return load_config()

    return config
