//
// Copyright 2022 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

syntax = "proto3";

package xds_client_fuzzer;

import "envoy/service/discovery/v3/discovery.proto";
import "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.proto";

// We'd ideally like to use google.rpc.Status instead of creating our
// own proto for this, but that winds up causing all sorts of dependency
// headaches.
message Status {
  int32 code = 1;
  string message = 2;
}

//
// interactions with XdsClient API
//

// Use a oneof instead of an enum so that we can ensure that the code
// will fail to build if we add a type here and don't handle it in the
// fuzzer code.
message ResourceType {
  message EmptyMessage {}
  oneof resource_type {
    EmptyMessage listener = 1;
    EmptyMessage route_config = 2;
    EmptyMessage cluster = 3;
    EmptyMessage endpoint = 4;
  }
}

message StartWatch {
  ResourceType resource_type = 1;
  string resource_name = 2;
}

message StopWatch {
  ResourceType resource_type = 1;
  string resource_name = 2;
}

// TODO(roth): add LRS methods on XdsClient

message DumpCsdsData {}

message ReportResourceCounts {}

message ReportServerConnections {}

//
// interactions with fake transport
//

message TriggerConnectionFailure {
  string authority = 1;
  Status status = 2;
}

message StreamId {
  string authority = 1;

  // Use a oneof instead of an enum so that we can ensure that the code
  // will fail to build if we add a type here and don't handle it in the
  // fuzzer code.
  message EmptyMessage {}
  oneof method {
    EmptyMessage ads = 2;
    EmptyMessage lrs = 3;
  }
}

message ReadMessageFromClient {
  StreamId stream_id = 1;
  bool ok = 2;
}

message SendMessageToClient {
  StreamId stream_id = 1;
  envoy.service.discovery.v3.DiscoveryResponse response = 2;
}

message SendStatusToClient {
  StreamId stream_id = 1;
  Status status = 2;
}

// Next free field: 10
message Action {
  oneof action_type {
    // interactions with XdsClient API
    StartWatch start_watch = 1;
    StopWatch stop_watch = 2;
    DumpCsdsData dump_csds_data = 3;
    ReportResourceCounts report_resource_counts = 8;
    ReportServerConnections report_server_connections = 9;
    // interactions with fake transport
    TriggerConnectionFailure trigger_connection_failure = 4;
    ReadMessageFromClient read_message_from_client = 5;
    SendMessageToClient send_message_to_client = 6;
    SendStatusToClient send_status_to_client = 7;
  }
}

message Msg {
  string bootstrap = 1;
  repeated Action actions = 2;
  fuzzing_event_engine.Actions fuzzing_event_engine_actions = 3;
}
