"""Runtime configuration for the HACCP generator service."""

from __future__ import annotations

import os
from dataclasses import dataclass
from pathlib import Path


@dataclass(frozen=True)
class AppConfig:
    """Environment-driven settings used by the Dockerized service."""

    drive_root_folder_id: str
    google_credentials: Path
    timezone: str = "Europe/Budapest"

    @classmethod
    def from_env(cls) -> "AppConfig":
        """Build configuration from environment variables with safe defaults."""

        credentials = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")
        if not credentials:
            raise RuntimeError("GOOGLE_APPLICATION_CREDENTIALS is required")

        root_folder_id = os.environ.get(
            "DRIVE_ROOT_FOLDER_ID", "1Y8LQJdU_8kYqZ8lidDHkFx0rjDoYXJci"
        )
        timezone = os.environ.get("TZ", "Europe/Budapest")

        return cls(
            drive_root_folder_id=root_folder_id,
            google_credentials=Path(credentials),
            timezone=timezone,
        )
