from pydantic import BaseModel, Field, ValidationError
from rich.console import Console
from typing import Dict, Any
from pathlib import Path
import typer


class ToolsConfig(BaseModel):
    apktool_jar_url: str
    apktool_wrapper_url: str


class Config(BaseModel):
    tools: ToolsConfig
    base: Dict[str, Any]


class PatchConfig(BaseModel):
    enabled: bool = Field(True, description="Включить или отключить патч")


def load_config(console: Console) -> Config:
    try:
        return Config.model_validate_json(Path("config.json").read_text())
    except FileNotFoundError:
        console.print("[red]Файл config.json не найден")
        raise typer.Exit(1)
    except ValidationError as e:
        console.print("[red]Ошибка валидации config.json:", e)
        raise typer.Exit(1)
