syntax = "proto3";

package voltha;

import "google/api/annotations.proto";

option java_package = "org.opencord.voltha";
option java_outer_classname = "VolthaProtos";
option csharp_namespace = "Opencord.Voltha.Voltha";

// Proto file and compiled descriptor for this interface
message Schema {

  // file name -> proto file content
  map<string, string> protos = 1;

  // file name -> gzip compressed protobuf of descriptor
  map<string, bytes> descriptors = 2;

}

// Empty message
message NullMessage {}

// Encode health status of a Voltha instance
message HealthStatus {

  // Health states
  enum HealthState {
    HEALTHY = 0;  // The instance is healthy
    OVERLOADED = 1;  // The instance is overloaded, decrease query rate
    DYING = 2;  // The instance is in a critical condition, do not use it
  }

  // Current state of health of this Voltha instance
  HealthState state = 1;

}

// Schema services
service SchemaService {

  // Return active grpc schemas
  rpc GetSchema(NullMessage) returns (Schema) {
    option (google.api.http) = {
      get: "/schema"
    };
  }
}

// Health related services
service HealthService {

  // Return current health status of a Voltha instance
  rpc GetHealthStatus(NullMessage) returns (HealthStatus) {
    option (google.api.http) = {
      get: "/health"
    };
  }

}

// (placeholder) Address as example message
message Address {
  string id = 7;  // ID of address record
  string street = 1;  // Street address
  string street2 = 2;  // Apartment, suite, building, etc.
  string street3 = 3;  // Apartment, suite, building, etc.
  string city = 4;  // City
  string state = 5;  // State
  uint32 zip = 6;   // Zip code
}

message Addresses {
  repeated Address addresses = 1;
}

// (placeholder) A more complex message type for testing purposes
message MoreComplex {
  HealthStatus health = 1; // Embedded health status
  int32 foo_counter = 2; // Counting foos
  string name = 3;  // Name of this thing
  repeated MoreComplex children = 4;  // Nested object to test recursion type
  Address address = 5;
}

// (placeholder) Convey an identifier
message ID {
  string id = 1;
}

// (placeholder) This is an example service
service ExampleService {

  // Return a bit more complex objects
  rpc ListAddresses(NullMessage) returns (Addresses) {
    option (google.api.http) = {
      get: "/addresses"
    };
  }

  // Return an address by ID
  rpc GetAddress(ID) returns (Address) {
    option (google.api.http) = {
      get: "/addresses/{id}"
    };
  }

  // Create an address record
  rpc CreateAddress(Address) returns (Address) {
    option (google.api.http) = {
      post: "/addresses"
      body: "*"
    };
  }

  // Delete an address record by ID
  rpc DeleteAddress(ID) returns (NullMessage) {
    option (google.api.http) = {
      delete: "/addresses/{id}"
    };
  }

}
