syntax = "proto3";

package gosdn.csbi;

import "gosdn/transport/transport.proto";

option go_package = "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi";

// only used from within the controller; therefore we do not provide
// grpc-gateway definitions
service CsbiService {
  rpc Get(GetRequest) returns (GetResponse);
  rpc GetFile(GetPayloadRequest) returns (stream Payload);
  rpc Create(CreateRequest) returns (CreateResponse);
  rpc CreateGoStruct(CreateRequest) returns (CreateResponse);
  rpc Delete(DeleteRequest) returns (DeleteResponse);
  rpc Hello(Syn) returns (Ack);
}

message Syn {
  int64 timestamp = 1;          // Timestamp in nanoseconds since Epoch.
  string id = 2;
  string address = 3;
}

message Ack {
  int64 timestamp = 1;          // Timestamp in nanoseconds since Epoch.
  .gosdn.transport.TransportOption transport_option = 2;
}

message GetRequest {
  int64 timestamp = 1;          // Timestamp in nanoseconds since Epoch.
  bool all = 2;
  repeated string did = 3;
}

message GetPayloadRequest {
  int64 timestamp = 1;          // Timestamp in nanoseconds since Epoch.
  string did = 2;
  string file = 3;
}

message GetResponse {
  int64 timestamp = 1;          // Timestamp in nanoseconds since Epoch.
  repeated Deployment deployments = 2;
}

message Deployment {
  string id = 1;
  string name = 2;
  State state = 3;
}

enum State {
  STATE_UNSPECIFIED = 0;
  STATE_ANNOUNCED = 1;
  STATE_BUILT = 2;
  STATE_DEPLOYED = 3;
  STATE_RUNNING = 4;
  STATE_DECOMMISSIONED = 5;
}

message CreateRequest {
  int64 timestamp = 1;          // Timestamp in nanoseconds since Epoch.
  repeated .gosdn.transport.TransportOption transport_option = 2;
}

message CreateResponse {
  int64 timestamp = 1;          // Timestamp in nanoseconds since Epoch.
  repeated Deployment deployments = 2;
}

message Payload {
  bytes chunk = 1;
}

message DeleteRequest {
  int64 timestamp = 1;          // Timestamp in nanoseconds since Epoch.
  repeated string did = 2;
}

message DeleteResponse {
  int64 timestamp = 1;          // Timestamp in nanoseconds since Epoch.
  enum Status {
    STATUS_UNSPECIFIED = 0;
    STATUS_OK = 1;
    STATUS_ERROR = 2;
  }
  Status status = 2;
}
