syntax = "proto3";
package proto;

option go_package = "./proto";

message Empty {}

message Settings {
    ConnectorConfig connector_config = 1;
}

message ConnectorConfig {
    string os = 1;
    string arch = 2;
    string protocol = 3;
    string username = 4;
    string password = 5;
    bytes key = 6;
    bool useStaticCredentials = 7;
    int64 keepalive = 8;
    int64 timeout = 9;
}

message InitRequest {
    bytes config = 1;
    Settings settings = 2;
}

message InitResponse {
    string id = 1;
    uint32 max_size = 2;
    string version = 3;
    string build_info = 4;
}

message UpdateResponse {
    string instance = 1;
    enum State {
        creating = 0;
        running = 1;
        deleting = 2;
        deleted = 3;
        timeout = 4;
    }
    State state = 2;
}

message IncreaseRequest {
    uint32 n = 1;
}

message IncreaseResponse {
    uint32 succeeded = 1;
}

message DecreaseRequest {
    repeated string instances = 1;
}

message DecreaseResponse {
    repeated string succeeded = 1;
}

message ConnectInfoRequest {
    string instance = 1;
}

message ConnectInfoResponse {
    ConnectorConfig connector = 1;
    string ExternalAddr = 2;
    string InternalAddr = 3;
    int64 expires = 4;
}

service InstanceGroup {
    rpc Init(InitRequest) returns (InitResponse);
    rpc Update(Empty) returns (stream UpdateResponse);
    rpc Increase(IncreaseRequest) returns (IncreaseResponse);
    rpc Decrease(DecreaseRequest) returns (DecreaseResponse);
    rpc ConnectInfo(ConnectInfoRequest) returns (ConnectInfoResponse);
    rpc Shutdown(Empty) returns (Empty);
}