//! Golden transcript fixtures for common ACP flows.
//!
//! These fixtures represent expected request/response sequences for testing.

use serde_json::json;

/// Golden transcript for initialize flow.
pub fn golden_initialize() -> serde_json::Value {
    json!({
        "request": {
            "jsonrpc": "2.0",
            "method": "initialize",
            "params": {
                "capabilities": {
                    "tools": true,
                    "streaming": true
                },
                "clientInfo": {
                    "name": "dirigent",
                    "version": "0.1.0"
                }
            },
            "id": 1
        },
        "response": {
            "jsonrpc": "2.0",
            "result": {
                "capabilities": {
                    "tools": ["read", "write", "edit", "search", "execute"],
                    "streaming": true,
                    "embeddedContext": true
                },
                "serverInfo": {
                    "name": "dirigate",
                    "version": "0.1.0"
                }
            },
            "id": 1
        }
    })
}

/// Golden transcript for new_session flow.
pub fn golden_new_session() -> serde_json::Value {
    json!({
        "request": {
            "jsonrpc": "2.0",
            "method": "session/new",
            "params": {
                "mode": "ask"
            },
            "id": 2
        },
        "response": {
            "jsonrpc": "2.0",
            "result": {
                "sessionId": "test-session-123"
            },
            "id": 2
        }
    })
}

/// Golden transcript for simple prompt flow.
pub fn golden_prompt() -> serde_json::Value {
    json!({
        "request": {
            "jsonrpc": "2.0",
            "method": "session/prompt",
            "params": {
                "sessionId": "test-session-123",
                "messages": [{
                    "role": "user",
                    "content": [
                        {
                            "type": "text",
                            "text": "Hello, agent!"
                        }
                    ]
                }]
            },
            "id": 3
        },
        "streaming_updates": [
            {
                "jsonrpc": "2.0",
                "method": "session/update",
                "params": {
                    "sessionId": "test-session-123",
                    "type": "agent_message_chunk",
                    "content": {
                        "text": "Hello! How can I help you?"
                    }
                }
            }
        ],
        "response": {
            "jsonrpc": "2.0",
            "result": {},
            "id": 3
        }
    })
}

/// Golden transcript for tool call flow (read file).
pub fn golden_tool_call_read() -> serde_json::Value {
    json!({
        "request": {
            "jsonrpc": "2.0",
            "method": "session/prompt",
            "params": {
                "sessionId": "test-session-123",
                "messages": [{
                    "role": "user",
                    "content": [
                        {
                            "type": "text",
                            "text": "Read the file test.txt"
                        }
                    ]
                }]
            },
            "id": 4
        },
        "streaming_updates": [
            {
                "jsonrpc": "2.0",
                "method": "session/update",
                "params": {
                    "sessionId": "test-session-123",
                    "type": "tool_call",
                    "content": {
                        "toolCallId": "tool-1",
                        "kind": "read",
                        "title": "Read test.txt",
                        "location": {
                            "path": "/path/to/test.txt"
                        }
                    }
                }
            },
            {
                "jsonrpc": "2.0",
                "method": "session/update",
                "params": {
                    "sessionId": "test-session-123",
                    "type": "tool_call_update",
                    "content": {
                        "toolCallId": "tool-1",
                        "status": "completed",
                        "result": {
                            "type": "content",
                            "content": "File content here"
                        }
                    }
                }
            },
            {
                "jsonrpc": "2.0",
                "method": "session/update",
                "params": {
                    "sessionId": "test-session-123",
                    "type": "agent_message_chunk",
                    "content": {
                        "text": "I've read the file. The content is: ..."
                    }
                }
            }
        ],
        "response": {
            "jsonrpc": "2.0",
            "result": {},
            "id": 4
        }
    })
}

/// Golden transcript for cancellation flow.
pub fn golden_cancel() -> serde_json::Value {
    json!({
        "request": {
            "jsonrpc": "2.0",
            "method": "session/cancel",
            "params": {
                "sessionId": "test-session-123"
            },
            "id": 5
        },
        "response": {
            "jsonrpc": "2.0",
            "result": {},
            "id": 5
        }
    })
}

/// Load a golden transcript by name.
pub fn load_golden_transcript(name: &str) -> Option<serde_json::Value> {
    match name {
        "initialize" => Some(golden_initialize()),
        "new_session" => Some(golden_new_session()),
        "prompt" => Some(golden_prompt()),
        "tool_call_read" => Some(golden_tool_call_read()),
        "cancel" => Some(golden_cancel()),
        _ => None,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_golden_transcripts_exist() {
        assert!(load_golden_transcript("initialize").is_some());
        assert!(load_golden_transcript("new_session").is_some());
        assert!(load_golden_transcript("prompt").is_some());
        assert!(load_golden_transcript("tool_call_read").is_some());
        assert!(load_golden_transcript("cancel").is_some());
        assert!(load_golden_transcript("nonexistent").is_none());
    }

    #[test]
    fn test_golden_initialize_structure() {
        let transcript = golden_initialize();
        assert!(transcript.get("request").is_some());
        assert!(transcript.get("response").is_some());
    }
}
