syntax = "proto2";

package Opal;

option java_package = "org.obiba.opal.web.model";

enum KeyType {
  KEY_PAIR = 0;
  CERTIFICATE = 1;
}

message KeyDto {
  required string alias = 1;
  required string certificate = 2;
  required KeyType keyType = 3;
}

message KeyForm {
  required string alias = 1;

  optional PrivateKeyForm privateForm = 2;
  optional string privateImport = 3;

  optional PublicKeyForm publicForm = 4;
  optional string publicImport = 5;
  optional string certificateFile = 6;

  required KeyType keyType = 7;
}

message PrivateKeyForm {
  required string algo = 1;
  required int32 size = 2;
}

message PublicKeyForm {
  required string name = 1;
  required string organizationalUnit = 2;
  required string organization = 3;
  required string locality = 4;
  required string state = 5;
  required string country = 6;
}

message FileDto {
  required string name = 1;
  required string path = 2;
  enum FileType {
    FILE = 0;
    FOLDER = 1;
  }
  required FileType type = 3;
  repeated FileDto children = 4;
  optional int64 size = 5;
  optional int64 lastModifiedTime = 6;
  required bool readable = 7;
  required bool writable = 8;
}

message LocaleDto {
  required string name = 1; // Locale.toString()
  optional string display = 2; // Locale.getDisplayName(clientLocale)
}

message ParameterDto {
  required string key = 1;
  required string value = 2;
}

message SuggestionsDto {
  required string query = 1;
  repeated string suggestions = 2;
}

message Subject {
  enum SubjectType {
    USER = 0;
    GROUP = 1;
  }
  required string principal = 1;
  required SubjectType type = 2;
  optional bool otpRequired = 3;
}

message Acl {
  required Subject subject = 1;
  required string resource = 2;
  repeated string actions = 3;
  required string domain = 4;
}

message Acls {
  required Subject subject = 1;
  repeated Acl acls = 2;
}

enum AclAction {
  DATASOURCE_ALL = 0;
  DATASOURCE_VIEW = 7;
  TABLE_ADD = 1;
  TABLE_ALL = 3;
  TABLE_READ = 4;
  TABLE_VALUES = 5;
  TABLE_EDIT = 6;
  VARIABLE_READ = 12;
  DATABASES_ALL = 13;
  R_USE = 14;
  DATASHIELD_ALL = 15;
  DATASHIELD_USE = 16;
  FILES_ALL = 18;
  FILES_READ = 19;
  FILES_SHARE = 20;
  PROJECT_ALL = 23;
  TABLE_VALUES_EDIT = 24;
  PROJECT_ADD = 25;
  SYSTEM_ALL = 26;
  VCF_STORE_VIEW = 27;
  VCF_STORE_VALUES = 28;
  VCF_STORE_ALL = 29;
  RESOURCES_ALL = 30;
  RESOURCES_VIEW = 31;
  RESOURCE_ALL = 32;
  RESOURCE_VIEW = 33;
  DATASHIELD_PROFILE_USE = 34;
}

message OpalMap {
  repeated string keys = 1;
  repeated string values = 2;
}

message EntryDto {
  required string key = 1;
  optional string value = 2;
  repeated string values = 3;
}


enum ServiceStatus {
  RUNNING = 1;
  STOPPED = 2;
}

message ServiceDto {
  required string name = 1;
  required ServiceStatus status = 2;
  required string link = 3;
}

message ServiceCfgDto {
  required string name = 1; // service name
  extensions 1000 to max;
}

message ESCfgDto {
  required string clusterName = 1;
  optional string indexName = 2;
  required bool dataNode = 3 [default = true];
  required int32 shards = 4;
  required int32 replicas = 5;
  optional string settings = 6;
  optional bool enabled = 7;
  extend ServiceCfgDto {
    optional ESCfgDto params = 1000;
  }
}

enum TableIndexationStatus {
  NOT_INDEXED = 1; // this table is not indexable
  OUTDATED = 2; // this table is indexable, index is not up-to-date and is not in progress
  IN_PROGRESS = 3; // this table is indexable, index is not up-to-date and is in progress
  UPTODATE = 4; // this table is indexable and index is up-to-date
}

message TableIndexStatusDto {
  required string datasource = 1;
  required string table = 2;
  optional string indexCreated = 3;
  optional string indexLastUpdate = 4;
  optional string tableLastUpdate = 5;
  required ScheduleDto schedule = 6; // if no schedule is defined in the index manager configuration, the default one is returned
  required TableIndexationStatus status = 7;
  optional float progress = 8;
  required string link = 9; // link to this index
}

enum ScheduleType {
  NOT_SCHEDULED = 1;
  MINUTES_5 = 2;
  MINUTES_15 = 3;
  MINUTES_30 = 4;
  HOURLY = 5;
  DAILY = 6;
  WEEKLY = 7;
}

enum Day {
  SUNDAY = 1;
  MONDAY = 2;
  TUESDAY = 3;
  WEDNESDAY = 4;
  THURSDAY = 5;
  FRIDAY = 6;
  SATURDAY = 7;
}

message ScheduleDto {
  required ScheduleType type = 1;
  optional Day day = 2;
  optional int32 hours = 3;
  optional int32 minutes = 4;
}

message PasswordDto {
  required string name = 1;
  required string oldPassword = 2;
  required string newPassword = 3;
}

message SubjectCredentialsDto {
  enum AuthenticationType {
    PASSWORD = 1;
    CERTIFICATE = 2;
  }
  required string name = 1;
  required AuthenticationType authenticationType = 2;
  optional string password = 3; // only set when the password is to be updated on POST or PUT
  optional bytes certificate = 4;
  repeated string groups = 5;
  optional bool enabled = 6 [default = true];
}

message GroupDto {
  required string name = 1;
  repeated string subjectCredentials = 2;
}

message SubjectProfileDto {
  required string principal = 1;
  required string realm = 2;
  required string created = 3;
  required string lastUpdate = 4;
  optional string accountUrl = 5;
  repeated string groups = 6;
  optional bool otpEnabled = 7 [default = false];
  optional bool otpRequired = 8;
}

message SubjectTokenDto {
  enum AccessType {
    READ_NO_VALUES = 0;
    READ = 1;
  }
  optional string principal = 1;
  optional string token = 2;
  required string name = 3;
  repeated string projects = 4;
  repeated string commands = 5;
  optional bool useR = 6 [default = false];
  optional bool useDatashield = 7 [default = false];
  optional bool useSQL = 8 [default = false];
  optional bool sysAdmin = 9 [default = false];
  optional string created = 10;
  optional string lastUpdate = 11;
  optional bool createProject = 12 [default = false];
  optional bool updateProject = 13 [default = false];
  optional bool deleteProject = 14 [default = false];
  optional AccessType access = 15;
  optional bool inactive = 16;
  optional string inactiveAt = 17;
  optional string expiresAt = 18;
}

message LinkDto {
  required string rel = 1;
  required string link = 2;
}

message BookmarkDto {
  enum ResourceType {
    PROJECT = 0;
    TABLE = 1;
    VARIABLE = 2;
  }
  required string resource = 1;
  required ResourceType type = 2;
  repeated LinkDto links = 3;
  required string created = 4;
}

// Extracts from RuntimeMXBean
message OpalEnv {
  required string version = 1; // opal version
  required string vmName = 2;
  required string vmVendor = 3;
  required string vmVersion = 4;
  required string javaVersion = 5;
  repeated EntryDto systemProperties = 6;
}

// Extracts from MemoryMXBean, ThreadMXBean and GarbageCollectorMXBeans
message OpalStatus {
  // http://docs.oracle.com/javase/7/docs/api/java/lang/management/MemoryUsage.html
  message MemoryUsage {
    required int64 init = 1;
    required int64 used = 2;
    required int64 committed = 3;
    required int64 max = 4;
  }
  message ThreadsUsage {
    required int64 count = 1;
    required int64 peak = 2;
  }
  message GarbageCollectorUsage {
    required string name = 1;
    required int64 collectionCount = 2;
    required int64 collectionTime = 3;
  }
  required int64 timestamp = 1;
  required int64 uptime = 2;
  required MemoryUsage heapMemory = 3;
  required MemoryUsage nonHeapMemory = 4;
  required ThreadsUsage threads = 5;
  repeated GarbageCollectorUsage gcs = 6;
}

message GeneralConf {
  required string name = 1 [default = "Opal"];
  repeated string languages = 2; // replaces the property org.obiba.opal.languages
  required string defaultCharSet = 3 [default = "ISO-8859-1"]; // replaces the property org.obiba.opal.charset.default
  optional string publicURL = 4;
  optional string logoutURL = 5;
  required bool enforced2FA = 6;
  required bool allowRPackageManagement = 7;
}

message AttributeConf {
  message Attr {
    required string name = 1;
    repeated string values = 2; // enumerated values if any
  }
  required string namespace = 1 [default = "opal"];
  optional string description = 2; // description of this set of attributes
  repeated Attr conf = 3;
}

message LocaleTextDto {
  required string locale = 1;
  required string text = 2;
}

message TermDto {
  required string name = 1;
  repeated LocaleTextDto title = 2;
  repeated LocaleTextDto description = 3;
  repeated TermDto terms = 4;
  repeated LocaleTextDto keywords = 5;
  repeated EntryDto attributes = 6;
}

message VocabularyDto {
  required string name = 1;
  repeated LocaleTextDto title = 2;
  repeated LocaleTextDto description = 3;
  required bool repeatable = 4 [default = false]; // allows the corresponding attribute name to be applied multiple times
  repeated TermDto terms = 5;
  repeated LocaleTextDto keywords = 6;
  repeated EntryDto attributes = 7;
}

message TaxonomiesDto {
  message TaxonomySummaryDto {
    message VocabularySummaryDto {
      required string name = 1;
      repeated LocaleTextDto title = 2;
    }

    required string name = 1;
    repeated LocaleTextDto title = 2;
    repeated VocabularySummaryDto vocabularySummaries = 3;
  }

  repeated TaxonomySummaryDto summaries = 1;
}

message TaxonomyDto {
  required string name = 1; // mapped to attribute namespace
  optional string author = 2;
  optional string license = 3;
  repeated LocaleTextDto title = 4;
  repeated LocaleTextDto description = 5;
  repeated VocabularyDto vocabularies = 6;
  repeated LocaleTextDto keywords = 7;
  repeated EntryDto attributes = 8;
}

message TaxonomyBundleDto {
  required string target = 1;
  required TaxonomyDto taxonomy = 2;
}

message OpalConf {
  required GeneralConf general = 1;
  repeated TaxonomyDto taxonomies = 2;
}

message VcsTagsInfoDto {
  repeated string names = 1;
}

message VcsCommitInfosDto {
  repeated VcsCommitInfoDto commitInfos = 1;
}

message VcsCommitInfoDto {
  required string author = 1;
  required string date = 2;
  required string comment = 3;
  required string commitId = 4;
  repeated string diffEntries = 5;
  optional string blob = 6;
  optional bool isHead = 7 [default = false]; // head of the commit tree
  optional bool isCurrent = 8 [default = false]; // current (latest) commit for a given path
}

message IDProviderDto {
  required string name = 1;
  optional string label = 2;
  optional string providerUrl = 3;
  required string clientId = 4;
  required string secret = 5;
  required string discoveryURI = 6;
  required string scope = 7;
  required bool useNonce = 8;
  optional int32 connectTimeout = 9;
  optional int32 readTimeout = 10;
  optional string groups = 11;
  optional string groupsClaim = 12;
  repeated ParameterDto parameters = 13;
  required bool enabled = 14;
  optional string usernameClaim = 15;
  optional string groupsScript = 16;
  optional string callbackURL = 17;
  optional bool useLogout = 18;
}

message AuthProviderDto {
  required string name = 1;
  optional string label = 2;
  optional string providerUrl = 3;
}

message NewsDto {
  message NoteDto {
    required string title = 1;
    required string link = 2;
    required string date = 3;
    optional string summary = 4;
  }
  repeated NoteDto notes = 1;
}