export type TreeRouteBoundaryRole =
  | "rust-owned"
  | "next-thin-proxy"
  | "legacy-thin-proxy"
  | "browser-substrate"
  | "compat-pending";

export type TreeRouteBoundaryItem = {
  id: string;
  role: TreeRouteBoundaryRole;
  route: string;
  owner: "rust-runtime" | "rust-web-gateway" | "next-app-router-legacy" | "convex-substrate";
  description: string;
};

export const TREE_3000_ROUTE_BOUNDARY_MANIFEST = {
  schema: "mnote.tree.3000_route_boundary",
  schemaVersion: 1,
  publicEntry: "3000",
  routes: [
    {
      id: "tree.commands",
      role: "rust-owned",
      route: "/api/tree/commands",
      owner: "rust-web-gateway",
      description:
        "浏览器公开树命令入口由 Rust Web gateway 拥有；legacy Next 仅保留 cookie/header compat 和浏览器 substrate 能力。",
    },
    {
      id: "tree.stream",
      role: "rust-owned",
      route: "/api/tree/stream",
      owner: "rust-web-gateway",
      description:
        "浏览器 SSE/polling 入口由 Rust Web gateway 拥有，legacy Next 只作为迁移期 alias。",
    },
    {
      id: "tree.shell.debug",
      role: "compat-pending",
      route: "/api/tree/shell",
      owner: "next-app-router-legacy",
      description:
        "仅服务显式 debug/internal runtime 验证；3000 主路径使用 same-origin inline host，不应默认请求 mnote-web:3104。",
    },
  ] satisfies TreeRouteBoundaryItem[],
  rustOwnedSemantics: [
    "tree.node.create",
    "tree.node.rename",
    "tree.subtree.move",
    "tree.node.archive",
    "tree.node.restore",
    "tree.node.purge",
    "tree.subtree.copy",
    "tree.node.embed",
  ],
  nextThinProxyDuties: [
    "cookie/auth 读取与 Convex client 获取",
    "workspace bootstrap",
    "legacy route alias 与 header 透传",
    "tree.subtree.move 的 sidebar snapshot preflight 数据采集",
  ],
  browserSubstrateDuties: [
    "新页面 scaffold 文件创建",
    "复制页面后的 mindmap 文件复制",
    "页面嵌入前读取目标内容、源页面标题与 anchor block，作为 Rust Page Aggregate embed plan 的 preflight substrate",
    "文件字节读取、upload URL、cookie/auth 等浏览器入口能力",
  ],
  compatPending: [] satisfies TreeRouteBoundaryItem[],
  forbiddenNextSemantics: [
    "树合法性判断",
    "树排序 canonical plan",
    "长期 streamDelta 主语义拼装",
    "tree shell renderer runtime",
    "tree.node.embed 的 pageReference block 结构与插入位置语义",
    "主 tree command transport owner",
    "主 tree stream transport owner",
  ],
} as const;
