"""LSP resource type definitions for the Resource Registry.

Contains the built-in LSP-related type entries (``executable``,
``lsp-server``, ``lsp-workspace``, ``lsp-document``) that are appended
to ``BUILTIN_TYPES`` in ``_resource_registry_data``.

These types bridge the resource system with the LSP runtime, allowing
actors to discover available language tooling and the LSP system to know
which resources it operates on.

Spec reference: docs/adr/ADR-039-container-resource-types.md (executable),
                docs/adr/ADR-040-lsp-resource-types.md (lsp-server,
                lsp-workspace, lsp-document)

.. note::

    This is an **internal** module (``_``-prefixed).  External code
    should import ``BUILTIN_TYPES`` from ``_resource_registry_data``
    instead.
"""

from __future__ import annotations

from typing import Any

__all__ = ["LSP_RESOURCE_TYPES"]

# === LSP Resource Types (#832) ===
#
# These types model language tooling infrastructure in the resource DAG.
# - executable: system binary / interpreter / LSP server binary
# - lsp-server: a configured or running LSP server instance
# - lsp-workspace: workspace root tracked by an LSP server
# - lsp-document: text document tracked by an LSP server

LSP_RESOURCE_TYPES: list[dict[str, Any]] = [
    # ── executable ───────────────────────────────────────────────
    {
        "name": "executable",
        "description": (
            "System executable (language runtime, compiler, LSP server "
            "binary). Discovered from container or host PATH."
        ),
        "resource_kind": "physical",
        "sandbox_strategy": "none",
        "user_addable": True,
        "built_in": True,
        "cli_args": [
            {
                "name": "path",
                "type": "string",
                "required": True,
                "description": "Absolute path to the executable",
            },
            {
                "name": "version",
                "type": "string",
                "required": False,
                "description": "Executable version if detectable",
            },
        ],
        "parent_types": ["container-exec-env", "fs-directory"],
        "child_types": [],
        "handler": "cleveragents.resource.handlers.executable:ExecutableHandler",
        "auto_discovery": {
            "trigger_types": ["container-exec-env", "fs-directory"],
            "scan_paths": [],
            "lazy": True,
        },
        "capabilities": {
            "read": True,
            "write": False,
            "sandbox": False,
            "checkpoint": False,
        },
    },
    # ── lsp-server ───────────────────────────────────────────────
    {
        "name": "lsp-server",
        "description": (
            "LSP server definition and running process. Provides "
            "semantic services for one or more languages."
        ),
        "resource_kind": "physical",
        "sandbox_strategy": "none",
        "user_addable": True,
        "built_in": True,
        "cli_args": [
            {
                "name": "server-name",
                "type": "string",
                "required": True,
                "description": "Unique server name",
            },
            {
                "name": "command",
                "type": "string",
                "required": True,
                "description": "Path to server executable or command",
            },
            {
                "name": "language-ids",
                "type": "string",
                "required": True,
                "description": (
                    "Comma-separated language identifiers (e.g. python,typescript)"
                ),
            },
            {
                "name": "transport",
                "type": "string",
                "required": False,
                "description": ("Transport: stdio | tcp | pipe (default: stdio)"),
            },
            {
                "name": "args",
                "type": "string",
                "required": False,
                "description": "Additional command-line arguments",
            },
            {
                "name": "port",
                "type": "string",
                "required": False,
                "description": "TCP port (required when transport=tcp)",
            },
            {
                "name": "initialization-options",
                "type": "string",
                "required": False,
                "description": "JSON initialization options for the server",
            },
        ],
        "parent_types": ["container-instance", "container-exec-env"],
        "child_types": ["lsp-workspace"],
        "handler": "cleveragents.resource.handlers.lsp:LSPServerHandler",
        "capabilities": {
            "read": True,
            "write": False,
            "sandbox": False,
            "checkpoint": False,
        },
    },
    # ── lsp-workspace ────────────────────────────────────────────
    {
        "name": "lsp-workspace",
        "description": (
            "Workspace root tracked by an LSP server. Corresponds to "
            "a workspaceFolder in the LSP specification."
        ),
        "resource_kind": "physical",
        "sandbox_strategy": "none",
        "user_addable": False,
        "built_in": True,
        "cli_args": [],
        "parent_types": ["lsp-server"],
        "child_types": ["lsp-document"],
        "handler": "cleveragents.resource.handlers.lsp:LSPWorkspaceHandler",
        "auto_discovery": {
            "trigger_types": ["lsp-server"],
            "scan_paths": [],
        },
        "capabilities": {
            "read": True,
            "write": False,
            "sandbox": False,
            "checkpoint": False,
        },
    },
    # ── lsp-document ─────────────────────────────────────────────
    {
        "name": "lsp-document",
        "description": (
            "Text document tracked by an LSP server. Provides semantic "
            "access: types, diagnostics, completions, references, symbols."
        ),
        "resource_kind": "physical",
        "sandbox_strategy": "none",
        "user_addable": False,
        "built_in": True,
        "cli_args": [],
        "parent_types": ["lsp-workspace"],
        "child_types": [],
        "handler": "cleveragents.resource.handlers.lsp:LSPDocumentHandler",
        "auto_discovery": {
            "trigger_types": ["lsp-workspace"],
            "scan_paths": [],
        },
        "capabilities": {
            "read": True,
            "write": True,
            "sandbox": False,
            "checkpoint": False,
        },
    },
]
