// Copyright 2020 Adap 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";

option java_multiple_files = true;
option java_package = "flwr.android_client";
option java_outer_classname = "FlowerTransport";
option objc_class_prefix = "gRPC";

package flower.transport;

service FlowerService {
    rpc Join(stream ClientMessage) returns (stream ServerMessage) {}
}

message Parameters {
    repeated bytes tensors = 1;
    string tensor_type = 2;
}
enum Reason {
    UNKNOWN = 0;
    RECONNECT = 1;
    POWER_DISCONNECTED = 2;
    WIFI_UNAVAILABLE = 3;
    ACK = 4;
}

message ServerMessage {
    message Reconnect { int64 seconds = 1; }
    message GetParameters {}
    message FitIns {
        Parameters parameters = 1;
        map<string, Scalar> config = 2;
    }
    message EvaluateIns {
        Parameters parameters = 1;
        map<string, Scalar> config = 2;
    }
    message PropertiesIns { map<string, Scalar> config = 1; }
    oneof msg {
        Reconnect reconnect = 1;
        GetParameters get_parameters = 2;
        FitIns fit_ins = 3;
        EvaluateIns evaluate_ins = 4;
        PropertiesIns properties_ins = 5;
    }
}

message ClientMessage {
    message Disconnect { Reason reason = 1; }
    message ParametersRes { Parameters parameters = 1; }
    message FitRes {
        Parameters parameters = 1;
        int64 num_examples = 2;
        int64 num_examples_ceil = 3 [ deprecated = true ];
        float fit_duration = 4 [ deprecated = true ];
        map<string, Scalar> metrics = 5;
    }
    message EvaluateRes {
        int64 num_examples = 1;
        float loss = 2;
        float accuracy = 3 [ deprecated = true ];
        map<string, Scalar> metrics = 4;
    }
    message PropertiesRes { map<string, Scalar> properties = 1; }
    oneof msg {
        Disconnect disconnect = 1;
        ParametersRes parameters_res = 2;
        FitRes fit_res = 3;
        EvaluateRes evaluate_res = 4;
        PropertiesRes properties_res = 5;
    }
}

message Scalar {
    // The following oneof contains all types that ProtoBuf considers to be
    // "Scalar Value Types". Commented-out types are listed for reference and
    // might be enabled in future releases. Source:
    // https://developers.google.com/protocol-buffers/docs/proto3#scalar
    oneof scalar {
        double double = 1;
        // float float = 2;
        // int32 int32 = 3;
        // int64 int64 = 4;
        // uint32 uint32 = 5;
        // uint64 uint64 = 6;
        // sint32 sint32 = 7;
        sint64 sint64 = 8;
        // fixed32 fixed32 = 9;
        // fixed64 fixed64 = 10;
        // sfixed32 sfixed32 = 11;
        // sfixed64 sfixed64 = 12;
        bool bool = 13;
        string string = 14;
        bytes bytes = 15;
    }
}