use serde_json::{json, Value};

pub const MANIFEST_SCHEMA_VERSION: &str = "mnote.hermes_tool_manifest.v1";
pub const TOOL_SCHEMA_VERSION: &str = "mnote.hermes_tool.v1";

pub fn manifest() -> Value {
    json!({
        "schemaVersion": MANIFEST_SCHEMA_VERSION,
        "plugin": {
            "name": "mnote",
            "description": "mnote 页面、树、artifact 与 edge 工具",
            "runtimeOwner": "mnote-web",
            "writeOwner": "rust-runtime-kernel"
        },
        "tools": [
            page_get_tool(),
            planned_tool("mnote.page.save", ["page.write"]),
            planned_tool("mnote.page.update_title", ["page.write"]),
            planned_tool("mnote.page.update_options", ["page.write"]),
            planned_tool("mnote.artifact.create_summary", ["artifact.write"]),
            planned_tool("mnote.artifact.create_ai_note", ["artifact.write"])
        ]
    })
}

fn page_get_tool() -> Value {
    json!({
        "name": "mnote.page.get",
        "description": "读取当前页面 Page Aggregate 摘要",
        "schemaVersion": TOOL_SCHEMA_VERSION,
        "capabilityScope": ["page.read"],
        "inputSchema": {
            "type": "object",
            "required": ["workspaceId", "documentId", "sessionId", "runId", "toolCallId", "traceId"],
            "properties": {
                "workspaceId": { "type": "string" },
                "documentId": { "type": "string" },
                "sessionId": { "type": "string" },
                "runId": { "type": "string" },
                "toolCallId": { "type": "string" },
                "traceId": { "type": "string" },
                "includeBody": { "type": "boolean", "default": true },
                "includeOptions": { "type": "boolean", "default": true },
                "includeBlocks": { "type": "boolean", "default": true }
            }
        }
    })
}

fn planned_tool(name: &str, scope: impl IntoIterator<Item = &'static str>) -> Value {
    json!({
        "name": name,
        "description": "已冻结合同，按 7-4 后续 task 接入 Rust runtime / kernel",
        "schemaVersion": TOOL_SCHEMA_VERSION,
        "capabilityScope": scope.into_iter().collect::<Vec<_>>(),
        "status": "planned"
    })
}
