syntax = "proto3";

package wix.devcenter.appsruntime.v1;
option java_package = "com.wixpress.devcenter.appsruntime.v1";

import "google/protobuf/wrappers.proto";
import "wix/api/validations.proto";
import "wix/api/entity.proto";
import "wix/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "components_catalog_data.proto";
import "com/wixpress/appservice/api/components_catalog_type.proto";
import "wix/devcenter/apps/dependencies/v2/app_dependency.proto";

message AppRuntimeDataCacheEntity {
  option (.wix.api.entity) = {
    fqdn: "wix.devcenter.v1.app_runtime_data_cache_entity"
    segment: PUBLIC
  };
  AppData app_data = 1;
  map<string, TranslatedData> translated_data_map = 2;

  message AppData {
    string app_id = 1 [(.wix.api.format) = GUID]; // Represents the ID of the Application
    string version = 2 [(.wix.api.maxLength) = 50]; // Represents the Version of the Application
    string name = 3 [(wix.api.maxLength) = 50]; // Represents the name of the Application
    string account_id = 4 [(.wix.api.format) = GUID]; // Represents the account id of the Application
    google.protobuf.StringValue namespace = 5 [(wix.api.minLength) = 1, (wix.api.maxLength) = 150]; //Represents the namespace of the application
    bool wix_app = 6; //Is Wix application?
    string status = 7 [(.wix.api.maxLength) = 50]; //The state of the application
    string app_type = 8 [(.wix.api.maxLength) = 50]; //The type of application
    repeated RuntimeComponentCacheEntity components = 9 [(.wix.api.maxSize) = 330]; //Represents the Component data enriched with translations and overrides
    google.protobuf.StringValue slug = 10 [(.wix.api.minLength) = 1, (wix.api.maxLength) = 200]; // The slug of the app. A human readable identifier of the app
    bool private_app = 11; // Indicates if the app is private
    CreatedByCacheEntity created_by = 12 ; // The id and type of the entity which created the App (User, App, etc.)
    google.protobuf.Timestamp created_date = 13 ; // Represents the time this AppRuntimeData was created
    google.protobuf.Timestamp updated_date = 14 ; // Represents the time this AppRuntimeData was last updated
    bool draft = 15; // Indicates if this app's version is not in draft state
    reserved 16; // Removed irrelevant "permissions" field
    google.protobuf.StringValue full_version = 17 [(wix.api.minLength) = 1, (.wix.api.maxLength) = 50]; // Represents the full version (major.minor.build) of the version. Only applicable for State = LOCKED_DRAFT / PRODUCTION
    google.protobuf.BoolValue hipaa_compliant = 18; // Indicates if the app is HIPAA compliant
    reserved 19; // Removed irrelevant "dependencies" field
    google.protobuf.BoolValue companion_app = 20; // Indicates if app is a Companion app
  }

  message TranslatedData {
    google.protobuf.StringValue name = 1;
    repeated RuntimeComponentCacheEntityComponent components = 2;
  }
}

message RuntimeComponentCacheEntity {
  oneof component {
    RuntimeComponentCacheEntityComponent component_entity = 1;
    RuntimeComponentCacheEntityExperiment component_experiment_entity = 2;
  }
}

message RuntimeComponentCacheEntityComponent {
  string component_id = 1 [(.wix.api.format) = GUID]; //The ID of the component
  int32 version = 2; //The version of the component
  google.protobuf.StringValue name = 3 [(.wix.api.maxLength) = 200]; // Component name
  com.wixpress.appservice.api.ComponentType type = 4; // the type of the component
  com.wixpress.appservice.api.ComponentData data = 5; // the data of the component
  google.protobuf.StringValue external_id = 7; // The external id of the component
  map<string, string> additional_translated_keys = 6; //The additional translated keys of the component
  google.protobuf.StringValue partial_update_patch = 8; // Partial update patch value
  google.protobuf.StringValue external_version = 9 [(wix.api.maxLength) = 64]; // The external version of the component, if exists. Related to the component's external_id.
}

message RuntimeComponentCacheEntityExperiment {
  string spec = 1 [(.wix.api.maxLength) = 128]; // Spec to conduct on the component
  string variant_value = 2 [(.wix.api.maxLength) = 128]; // Value the spec should return in order to return the newer component version

  oneof experiment {
    GradualRolloutCacheEntity gradual_rollout = 3;
    GradualUpdateCacheEntity gradual_update = 4;
    GradualDeleteCacheEntity gradual_delete = 5;
    PartialUpdateCacheEntity partial_update = 6;
  }

  message GradualRolloutCacheEntity {
    RuntimeComponentCacheEntityComponent experiment_component = 1;
  }

  message GradualUpdateCacheEntity {
    RuntimeComponentCacheEntityComponent experiment_component = 1;
    RuntimeComponentCacheEntityComponent fallback_component = 2;
  }

  message GradualDeleteCacheEntity {
    RuntimeComponentCacheEntityComponent experiment_component = 1;
  }

  message PartialUpdateCacheEntity {
    RuntimeComponentCacheEntityComponent experiment_component = 1;
  }
}

message CreatedByCacheEntity {
  string id = 1 [(wix.api.format) = GUID]; // The id of the entity which created the App
  string type = 2; //The type of the entity which created the App (User, App, etc.)
}

message AppPermissions {
  option (.wix.api.unwrap_array_value) = true;
  repeated string permissions = 1 [(.wix.api.maxSize) = 700, (wix.api.maxLength) = 164]; // List of the permissions of the app version
}

message RuntimeAppDependencyCacheEntity {
  int64 version = 1; // The version of AppDependency.
  wix.devcenter.apps.dependencies.v2.DependencyNode dependencies = 2; // The dependencies of the dependent app.
}