"""Configuration loading for the app.

Configuration is intentionally environment/.env based so credentials stay out of
source control and the same package can be reused by different frontends or
process managers.
"""

from __future__ import annotations

import os
from dataclasses import dataclass
from pathlib import Path

from dotenv import load_dotenv

load_dotenv()


@dataclass(frozen=True)
class JellyfinConfig:
    """Jellyfin connection settings."""

    url: str = os.getenv("JELLYFIN_URL", "")
    api_key: str = os.getenv("JELLYFIN_API_KEY", "")
    user_id: str = os.getenv("JELLYFIN_USER_ID", "")


@dataclass(frozen=True)
class SSHConfig:
    """SSH connection settings for remote file/resource access."""

    host: str = os.getenv("SSH_HOST", "")
    username: str = os.getenv("SSH_USERNAME", "")
    port: int = int(os.getenv("SSH_PORT", "22"))
    key_filename: str = os.getenv("SSH_KEY_FILENAME", str(Path.home() / ".ssh" / "id_rsa"))
    password: str = os.getenv("SSH_PASSWORD", "")
    media_root: str = os.getenv("REMOTE_MEDIA_ROOT", "")
    path_prefix: str = os.getenv("REMOTE_PATH_PREFIX", "")


@dataclass(frozen=True)
class AppConfig:
    jellyfin: JellyfinConfig = JellyfinConfig()
    ssh: SSHConfig = SSHConfig()


def load_config() -> AppConfig:
    """Build an AppConfig snapshot from the current environment/.env file."""
    return AppConfig()
