// Copyright 2020 The Ray 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 ray.rpc;

enum Type { DEFAULT = 0; }

message Arg {
  enum Locality {
    INTERNED = 0;
    REFERENCE = 1;
  }
  Locality local = 1;
  bytes reference_id = 2;
  bytes data = 3;
  Type type = 4;
}

message ClientTask {
  enum RemoteExecType {
    FUNCTION = 0;
    ACTOR = 1;
    METHOD = 2;
    STATIC_METHOD = 3;
  }
  RemoteExecType type = 1;
  string name = 2;
  bytes payload_id = 3;
  repeated Arg args = 4;
}

message ClientTaskTicket {
  bytes return_id = 1;
}

message PutRequest {
  bytes data = 1;
}

message PutResponse {
  bytes id = 1;
}

message GetRequest {
  bytes id = 1;
}

message GetResponse {
  bool valid = 1;
  bytes data = 2;
}
message WaitRequest {
  repeated bytes object_refs = 1;
  int64 num_returns = 2;
  double timeout = 3;
}

message WaitResponse {
  bool valid = 1;
  repeated bytes ready_object_ids = 2;
  repeated bytes remaining_object_ids = 3;
}

service RayletDriver {
  rpc GetObject(GetRequest) returns (GetResponse) {
  }
  rpc PutObject(PutRequest) returns (PutResponse) {
  }
  rpc WaitObject(WaitRequest) returns (WaitResponse) {
  }
  rpc Schedule(ClientTask) returns (ClientTaskTicket) {
  }
}

service RayletWorkerConnection {
  rpc Workstream(stream WorkStatus) returns (stream Work) {}
}

message WorkStatus {
  enum StatusCode {
    COMPLETE = 0;
    ERROR = 1;
    READY = 2;
  }
  StatusCode status = 1;
  bytes complete_data = 2;
  ClientTaskTicket finished_ticket = 3;
  string error_msg = 4;
}

message Work {
  ClientTask task = 1;
  ClientTaskTicket ticket = 2;
}
