use folk_plugin_grpc::GrpcEnvelope;

#[tokio::test]
async fn grpc_envelope_serializes_correctly() {
    let env = GrpcEnvelope {
        service: "mypackage.MyService".into(),
        method: "SayHello".into(),
        payload: b"\x0a\x05world".to_vec(),
    };

    let encoded = rmp_serde::to_vec_named(&env).unwrap();
    let decoded: GrpcEnvelope = rmp_serde::from_slice(&encoded).unwrap();
    assert_eq!(decoded.service, env.service);
    assert_eq!(decoded.method, env.method);
    assert_eq!(decoded.payload, env.payload);
}

#[tokio::test]
async fn grpc_envelope_deserializes_from_php_style_msgpack() {
    // PHP msgpack_pack with named keys produces the same format
    let env = GrpcEnvelope {
        service: "test.Service".into(),
        method: "DoThing".into(),
        payload: vec![1, 2, 3],
    };

    let encoded = rmp_serde::to_vec_named(&env).unwrap();
    let decoded: rmpv::Value = rmp_serde::from_slice(&encoded).unwrap();

    // Verify it's a map with string keys (compatible with PHP msgpack)
    let map = decoded.as_map().expect("should be a map");
    assert_eq!(map.len(), 3);
}

#[tokio::test]
#[ignore = "requires php + protobuf extension + grpcurl"]
async fn grpc_plugin_handles_unary_call() {
    // Start Folk with GrpcPlugin
    // Use grpcurl or a tonic client to call a method
    // Verify PHP side receives correct service/method/payload
    todo!()
}
