"""Pydantic models for CLI command arguments.

Replaces raw argparse.Namespace + getattr() with typed, validated models.
Each model is constructed from ``vars(argparse.Namespace)`` via ``model_validate``,
so ``extra="ignore"`` drops internal argparse fields like ``command``.
"""

from __future__ import annotations

from pydantic import BaseModel, Field


class _CLIArgs(BaseModel):
    """Base for all CLI arg models — ignores extra argparse fields."""

    model_config = {"extra": "ignore"}


class ServerConnArgs(_CLIArgs):
    """Common server connection arguments shared by many commands."""

    host: str = "127.0.0.1"
    port: int = 8080


class RunArgs(ServerConnArgs):
    """Arguments for ``albus run``."""

    target: str
    input: str | None = None
    server: bool = False


class ChatArgs(ServerConnArgs):
    """Arguments for ``albus chat``."""

    message: str
    agent: str = "host"


class ToolCallArgs(_CLIArgs):
    """Arguments for ``albus tool``."""

    tool_name: str
    tool_args: list[str] = Field(default_factory=list)


class PathwayArgs(ServerConnArgs):
    """Arguments for ``albus pathway <action>``."""

    action: str
    id: str | None = None
    target: str | None = None
    mode: str = "dag"
    output: str | None = None


class ListArgs(ServerConnArgs):
    """Arguments for ``albus list <resource>``."""

    resource: str
    category: str | None = None


class ConfigArgs(_CLIArgs):
    """Arguments for ``albus config <action>``."""

    action: str
    config: str | None = None


class InitArgs(_CLIArgs):
    """Arguments for ``albus init``."""

    minimal: bool = False
    scan: str | None = None
    namespace: str | None = None


class ServerArgs(_CLIArgs):
    """Arguments for ``albus server``."""

    host: str = "127.0.0.1"
    port: int = 8080
    debug: bool = False
    log_level: str = ""


class StudioArgs(_CLIArgs):
    """Arguments for ``albus studio``."""

    host: str = "127.0.0.1"
    port: int = 8080
    thread_id: str = "default"


class ValidateArgs(_CLIArgs):
    """Arguments for ``albus validate``."""

    target: str
    verbose: bool = False
    stop_on_fail: bool = False
