from __future__ import annotations

import os
from dataclasses import dataclass
from urllib.parse import urljoin

import cv2


autogen_warning = """# NOTE: This file was auto-generated by the refactor.
# Do not edit directly unless you know what you are doing.
"""

__all__ = ["BatchRecorderConfig"]


@dataclass
class BatchRecorderConfig:
    """Centralised configuration for the screen-recorder client.

    All values are sourced from environment variables so that the VM can be
    re-configured at runtime without any code changes, per the user's
    preference.
    """

    # REST API ----------------------------------------------------------------
    api_base_url: str = os.getenv("BACKEND_API_BASE_URL", "")
    batch_path: str = os.getenv("CUA_RECORDER_BATCH_PATH", "screenshare/image-batch")
    log_path: str = os.getenv("CUA_RECORDER_LOG_PATH", "screenshare/key-logs")

    # Recorder behaviour ------------------------------------------------------
    capture_interval: float = float(os.getenv("CUA_RECORDER_INTERVAL", "1"))  # seconds
    batch_size: int = int(os.getenv("CUA_RECORDER_BATCH_SIZE", "10"))

    # Authentication ----------------------------------------------------------
    secret_key: str = os.getenv("SECRET_KEY", "")

    # Optional local debugging ------------------------------------------------
    save_dir: str = os.getenv("CUA_RECORDER_SAVE_DIR", "")

    # Recording session ID is injected by ScreenCaptureController -------------
    session_id: int = 0

    # Overlay styling ---------------------------------------------------------
    bar_height: int = 40
    green_seconds: int = 1
    key_lifetime: int = 3
    font: int = cv2.FONT_HERSHEY_SIMPLEX
    font_scale: float = 1.0
    font_thickness: int = 2
    left_margin: int = 10

    # ---------------------------------------------------------------------
    # Computed properties
    # ---------------------------------------------------------------------

    @property
    def batch_endpoint(self) -> str:
        return urljoin(self.api_base_url.rstrip("/") + "/", self.batch_path.lstrip("/"))

    @property
    def log_endpoint(self) -> str:
        return urljoin(self.api_base_url.rstrip("/") + "/", self.log_path.lstrip("/")) 