/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * 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 cuttlefish.cvd;

message Status {
  // Subset of status codes from gRPC.
  enum Code {
    OK = 0;
    FAILED_PRECONDITION = 9;
    INTERNAL = 13;
  }

  Code code = 1;
  string message = 2;
}

message Request {
  oneof contents {
    // Returns the version of the CvdServer.
    VersionRequest version_request = 1;
    // Requests the CvdServer to shutdown.
    ShutdownRequest shutdown_request = 2;
    // Requests the CvdServer to execute a command on behalf of the client.
    CommandRequest command_request = 3;
  }
}

message Response {
  Status status = 1;
  oneof contents {
    VersionResponse version_response = 2;
    ShutdownResponse shutdown_response = 3;
    CommandResponse command_response = 4;
  }
}

message Version {
  int32 major = 1;
  int32 minor = 2;
  string build = 3;
  uint32 crc32 = 4;
}

message VersionRequest {}
message VersionResponse {
  Version version = 1;
}

message ShutdownRequest {
  // If true, clears instance and assembly state before shutting down.
  bool clear = 1;
}
message ShutdownResponse {}

enum WaitBehavior {
  WAIT_BEHAVIOR_UNKNOWN = 0;
  WAIT_BEHAVIOR_START = 1;
  WAIT_BEHAVIOR_COMPLETE = 2;
}

message CommandRequest {
  // The args that should be executed, including the subcommand.
  repeated string args = 1;
  // Environment variables that will be used by the subcommand.
  map<string, string> env = 2;
  string working_directory = 3;
  WaitBehavior wait_behavior = 4;
}
message CommandResponse {}
