syntax = "proto3";

import "google/api/annotations.proto";

// Apps is the master service that svc provides. It allows a user to list, create, update
service Apps {
  rpc List(AppsListParams) returns (AppsList) {
    option (google.api.http) = {
      get: "/api/v1/apps/list"
    };
  }

  rpc Create(Manifest) returns (App) {
    option (google.api.http) = {
      post: "/api/v1/apps/create"
      body: "*"
    };
  }

  rpc Update(AppUpdate) returns (App) {
    option (google.api.http) = {
      post: "/api/v1/apps/{name}/update"
      body: "*"
    };
  }

  rpc Inspect(AppInspect) returns (App) {
    option (google.api.http) = {
      get: "/api/v1/apps/{name}/inspect"
    };
  }

  rpc Delete(AppDelete) returns(Ok) {
    option (google.api.http) = {
      delete: "/api/v1/apps/{name}/delete"
    };
  }
}

message AppsListParams {
  string labelKey = 1;
  string labelVal = 2;

  // will be matched to app names
  string name = 3;
}

message AppsList {
  string message = 1;
  repeated App apps = 2;
}

message Manifest {
  map<string, string> environment = 1;
  map<string, string> labels = 2;
  string dockerImage = 3;
  string name = 4;
}

message App {
  string id = 1;
  string name = 2;
  string dockerImage = 3;
  map<string, string> environment = 4;
  map<string, string> labels = 5;
  repeated string authorizedUsers = 6;
  int32 instances = 7;
  string status = 8;
}

message AppUpdate {
  string name = 1;

  string newImage = 2;
  map<string, string> envAdd = 3;
  repeated string envRm = 4;
  map<string, string> labelAdd = 5;
  map<string, string> labelRm = 6;

  repeated string grantUsers = 7;
  repeated string revokeUsers = 8;
  int32 newInstanceCount = 9;
}

message AppInspect {
  string name = 1;
}

message AppDelete {
  string name = 1;
}

message Ok {
  string message = 1;
}
