syntax = "proto3";

// If you make any changes make sure you run: make regenerate-proto

package gitlab.agent.grpctool;

option go_package = "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v18/internal/tool/grpctool";

import "gitlab/agent/tool/streamvisitor/automata/automata.proto";
import "internal/tool/prototool/prototool.proto";
import "buf/validate/validate.proto";
import "google/protobuf/any.proto";

message HttpRequest {
  // First message of the stream.
  message Header {
    prototool.HttpRequest request = 1 [(buf.validate.field).required = true];
    // Optional extra information about the HTTP request.
    google.protobuf.Any extra = 2;
    // content_length contains the size of the expected body (if any) in the request.
    // Possible values are:
    // * -1:  if the body size cannot be determined, but there is a body (e.g. chunked)
    // * 0:   there is no body in the request
    // * > 0: the actual size of the body in bytes
    optional int64 content_length = 3 [(buf.validate.field).int64.gte = -1];
  }
  // Subsequent messages of the stream.
  message Data {
    // A chunk of request body.
    bytes data = 1;
  }
  // Last message of the stream if no UpgradeData is sent.
  message Trailer {
  }
  // Last message of the stream.
  // This is to support streaming requests that send an "Upgrade: ..." header.
  // https://datatracker.ietf.org/doc/html/rfc7230#section-6.7
  message UpgradeData {
    // A chunk of upgraded connection data.
    bytes data = 1;
  }
  oneof message {

    option (gitlab.agent.streamvisitor.automata.first_allowed_field) = 1;
    option (buf.validate.oneof).required = true;

    Header header = 1 [
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 2,
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 3
    ];
    Data data = 2 [
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 2,
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 3
    ];
    Trailer trailer = 3 [
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 4,
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = -1
    ];
    UpgradeData upgradeData = 4 [
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 4,
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = -1
    ];
  }
}

message HttpResponse {
  // First message of the stream.
  message Header {
    prototool.HttpResponse response = 1 [(buf.validate.field).required = true];
  }
  // Subsequent messages of the stream.
  message Data {
    // A chunk of response body.
    bytes data = 1;
  }
  // Last message of the stream if no UpgradeData is received.
  message Trailer {
  }
  // Last message of the stream.
  // This is to support streaming requests that send an "Upgrade: ..." header.
  // https://datatracker.ietf.org/doc/html/rfc7230#section-6.7
  message UpgradeData {
    // A chunk of upgraded connection data.
    bytes data = 1;
  }
  oneof message {

    option (gitlab.agent.streamvisitor.automata.first_allowed_field) = 1;
    option (buf.validate.oneof).required = true;

    Header header = 1 [
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 2,
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 3
    ];
    Data data = 2 [
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 2,
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 3
    ];
    Trailer trailer = 3 [
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 4,
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = -1
    ];
    UpgradeData upgradeData = 4 [
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = 4,
      (gitlab.agent.streamvisitor.automata.next_allowed_field) = -1
    ];
  }
}
