syntax = "proto3";
package mqbridge;

service Bridge {
    // Publishes a message to the bridge
    rpc Publish (BridgeMessage) returns (PublishResponse);
    // Publishes a batch of messages using a client stream
    rpc PublishBatch (stream BridgeMessage) returns (stream PublishResponse);
    // Subscribes to a stream of messages from the bridge
    rpc Subscribe (SubscribeRequest) returns (stream BridgeMessage);
    // Consumer -> Broker: explicit ack/nack for received messages
    rpc Acknowledge (Ack) returns (AckResponse);
}

message BridgeMessage {
    bytes payload = 1;
    string id = 2;
    map<string, string> metadata = 3;
}

message PublishResponse {
    // Reserve low field numbers that were used previously to avoid
    // accidental wire-compatibility breakage if older clients/servers
    // used those numbers for different semantics.
    reserved 1, 2, 3;

    oneof result {
        BridgeMessage reply = 10;
        Ack ack = 11;
        string error = 12;
    }
}

message Ack {
    string id = 1;
    enum Status {
        // Ack by default - this is already the name of the message
        ACK = 0;
        NACK = 1;
        REQUEUE = 2;
    }
    Status status = 2;
    string reason = 3;
    map<string, string> metadata = 4;
}
message AckResponse {
    bool success = 1;
    string error = 2;
}

message SubscribeRequest {
    string topic = 1;
}
