// Copyright 2023 Yunseong Hwang
//
// 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.
//
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";

service Active {
  rpc Describe(DescribeRequest) returns (DescribeResponse) {}
  rpc GetProperty(GetPropertyRequest) returns (GetPropertyResponse) {}
  rpc SetProperty(SetPropertyRequest) returns (SetPropertyResponse) {}
  rpc InvokeMethod(InvokeMethodRequest) returns (InvokeMethodResponse) {}
  rpc ConnectEvent(ConnectEventRequest) returns (ConnectEventResponse) {}
  rpc DisconnectEvent(DisconnectEventRequest)
      returns (DisconnectEventResponse) {}
  rpc HandleEvent(stream HandleEventResponse)
      returns (stream HandleEventRequest) {}
}

enum RequestContext {
  DEFAULT = 0;
  EVENT_CALLBACK = 1;
}

message DescribeRequest {
  RequestContext request_context = 1;
  uint32 callback_event_index = 2;
}

message PropertyInfo {
  uint32 index = 1;
  string name = 2;
  string property_type = 3;
}

message ArgumentInfo {
  string name = 1;
  string argument_type = 2;
}

message MethodInfo {
  uint32 index = 1;
  string name = 2;
  repeated ArgumentInfo arguments = 3;
  string return_type = 4;
}

message EventInfo {
  uint32 index = 1;
  string name = 2;
  repeated ArgumentInfo arguments = 3;
}

message DescribeResponse {
  repeated PropertyInfo properties = 1;
  repeated MethodInfo methods = 2;
  repeated EventInfo events = 3;
}

message VariantList { repeated Variant values = 1; }

message VaraintHashMap { map<string, Variant> values = 1; }

message Variant {
  oneof value {
    bool bool_value = 1;
    string string_value = 2;
    int32 int_value = 3;
    uint32 uint_value = 4;
    double double_value = 5;
    VariantList list_value = 6;
    VaraintHashMap map_value = 7;
  }
}

message GetPropertyRequest {
  uint32 index = 1;
  RequestContext request_context = 2;
  uint32 callback_event_index = 3;
}

message GetPropertyResponse { Variant value = 1; }

message SetPropertyRequest {
  uint32 index = 1;
  Variant value = 2;
  RequestContext request_context = 3;
  uint32 callback_event_index = 4;
}

message SetPropertyResponse {}

message InvokeMethodRequest {
  uint32 index = 1;
  repeated Variant arguments = 2;
  RequestContext request_context = 3;
  uint32 callback_event_index = 4;
}

message InvokeMethodResponse { Variant return_value = 1; }

message ConnectEventRequest {
  uint32 index = 1;
  RequestContext request_context = 2;
  uint32 callback_event_index = 3;
}

message ConnectEventResponse { bool successful = 1; }

message DisconnectEventRequest {
  uint32 index = 1;
  RequestContext request_context = 2;
  uint32 callback_event_index = 3;
}

message DisconnectEventResponse { bool successful = 1; }

message HandleEventRequest {
  uint32 index = 1;
  uint32 id = 2;
  repeated Variant arguments = 3;
}

message HandleEventResponse {
  uint32 index = 1;
  uint32 id = 2;
}
