// Copyright 2022 Flower Labs GmbH. All Rights Reserved.
//
// 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 flwr.proto;

import "flwr/proto/node.proto";
import "flwr/proto/task.proto";
import "flwr/proto/run.proto";

service Fleet {
  rpc CreateNode(CreateNodeRequest) returns (CreateNodeResponse) {}
  rpc DeleteNode(DeleteNodeRequest) returns (DeleteNodeResponse) {}
  rpc Ping(PingRequest) returns (PingResponse) {}

  // Retrieve one or more tasks, if possible
  //
  // HTTP API path: /api/v1/fleet/pull-task-ins
  rpc PullTaskIns(PullTaskInsRequest) returns (PullTaskInsResponse) {}

  // Complete one or more tasks, if possible
  //
  // HTTP API path: /api/v1/fleet/push-task-res
  rpc PushTaskRes(PushTaskResRequest) returns (PushTaskResResponse) {}

  rpc GetRun(GetRunRequest) returns (GetRunResponse) {}
}

// CreateNode messages
message CreateNodeRequest { double ping_interval = 1; }
message CreateNodeResponse { Node node = 1; }

// DeleteNode messages
message DeleteNodeRequest { Node node = 1; }
message DeleteNodeResponse {}

// Ping messages
message PingRequest {
  Node node = 1;
  double ping_interval = 2;
}
message PingResponse { bool success = 1; }

// PullTaskIns messages
message PullTaskInsRequest {
  Node node = 1;
  repeated string task_ids = 2;
}
message PullTaskInsResponse {
  Reconnect reconnect = 1;
  repeated TaskIns task_ins_list = 2;
}

// PushTaskRes messages
message PushTaskResRequest { repeated TaskRes task_res_list = 1; }
message PushTaskResResponse {
  Reconnect reconnect = 1;
  map<string, uint32> results = 2;
}

message Reconnect { uint64 reconnect = 1; }
