"""Canonical automation command catalog shared by Core policy and adapters.

The catalog separates project-scoped app commands from Core-owned control-plane
commands. Control-plane commands are deliberately not accepted by the Cloud
record executor.
"""
from __future__ import annotations

from typing import Literal, TypedDict


class CommandDefinition(TypedDict):
    scope: Literal["project", "workspace"]
    owner: Literal["cloud", "core"]
    sensitive: bool
    requires_user_principal: bool


APP_COMMANDS: dict[str, CommandDefinition] = {
    "content.page.create": {"scope": "project", "owner": "cloud", "sensitive": False, "requires_user_principal": False},
    "content.page.update": {"scope": "project", "owner": "cloud", "sensitive": False, "requires_user_principal": False},
    "content.post.create": {"scope": "project", "owner": "cloud", "sensitive": False, "requires_user_principal": False},
    "content.post.update": {"scope": "project", "owner": "cloud", "sensitive": False, "requires_user_principal": False},
    "content.navigation.update": {"scope": "project", "owner": "cloud", "sensitive": False, "requires_user_principal": False},
    "content.publish": {"scope": "project", "owner": "cloud", "sensitive": True, "requires_user_principal": True},
}

CONTROL_PLANE_COMMANDS: dict[str, CommandDefinition] = {
    "workspace.create": {"scope": "workspace", "owner": "core", "sensitive": True, "requires_user_principal": True},
    "workspace.member.invite": {"scope": "workspace", "owner": "core", "sensitive": True, "requires_user_principal": True},
    "project.create": {"scope": "workspace", "owner": "core", "sensitive": True, "requires_user_principal": True},
    "project.archive": {"scope": "workspace", "owner": "core", "sensitive": True, "requires_user_principal": True},
    "project.deploy": {"scope": "workspace", "owner": "core", "sensitive": True, "requires_user_principal": True},
}

COMMAND_CATALOG: dict[str, CommandDefinition] = {**APP_COMMANDS, **CONTROL_PLANE_COMMANDS}


def command_definition(command: str) -> CommandDefinition | None:
    return COMMAND_CATALOG.get(command)
