import os
from dataclasses import dataclass


@dataclass
class Settings:
    # Hotkeys (Windows format for `keyboard` lib)
    shortcut_capture: str = "alt+shift+1"
    shortcut_send: str = "alt+shift+2"
    shortcut_action3: str = "alt+shift+3"
    shortcut_reset: str = "alt+shift+4"
    shortcut_quit: str = "alt+shift+5"
    shortcut_toggle_mode: str = "alt+shift+6"

    # OpenAI
    model: str = "Google Gemini_2.5"
    prompt: str = (
        "You are a helpful assistant. Analyze the images and answer clearly."
    )
    retries: int = 3
    request_timeout_s: int = 60
    # Configurable API base and key. If left empty, env vars are used.
    # Typical base: https://api.openai.com/v1
    endpoint_base: str = "https://api.muzhen.org/v1"
    api_key: str = "falconfang"

    # Typing and clipboard behavior
    type_interval_s: float = 0.015

    # Data storage
    app_dir: str = os.path.join(
        os.environ.get("LOCALAPPDATA", os.path.expanduser("~/.local/share")),
        "BgVisionAgent",
    )
    captures_dir_name: str = "captures"
    response_file_name: str = "response.txt"
    log_file_name: str = "agent.log"


def ensure_dirs(cfg: Settings) -> None:
    os.makedirs(cfg.app_dir, exist_ok=True)
    os.makedirs(os.path.join(cfg.app_dir, cfg.captures_dir_name), exist_ok=True)


def data_paths(cfg: Settings):
    captures_dir = os.path.join(cfg.app_dir, cfg.captures_dir_name)
    response_path = os.path.join(cfg.app_dir, cfg.response_file_name)
    log_path = os.path.join(cfg.app_dir, cfg.log_file_name)
    return captures_dir, response_path, log_path
