syntax = "proto3";

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

import "google/protobuf/wrappers.proto";
import "wix/api/annotations.proto";
import "wix/api/entity.proto";
import "wix/api/validations.proto";
import "google/protobuf/timestamp.proto";
import "components_catalog_data.proto";

/**
  ComponentExperiment is the main entity of ComponentExperiments that can be used for deciding the component version during runtime
 */
message ComponentExperiment {
  option (.wix.api.entity) = {
    fqdn: "wix.devcenter.components_experiments.v1.component_experiment"
    segment: USERS
    appendix_files: {
      type: DOCS_CONF
      path: "appendices/docs"
    };
    app_def_id: "7edb7860-dc51-4416-85aa-0d3303515b33"
  };
  string app_id = 1 [(.wix.api.format) = GUID]; // App id of the component experiment
  string component_id = 2 [(.wix.api.format) = GUID]; // component id of the component experiment
  string spec = 3 [(.wix.api.maxLength) = 128]; // Spec to conduct on the component
  google.protobuf.StringValue variant_value = 4 [(.wix.api.maxLength) = 128]; // Value the spec should return in order to return the newer component version
  google.protobuf.Timestamp created_date = 5 [(wix.api.readOnly) = true]; // Date created
  google.protobuf.Timestamp updated_date = 6 [(wix.api.readOnly) = true]; // Date updated
  ExperimentType experiment_type = 7 [deprecated = true, (.wix.api.field_deprecated) = {
    replaced_by: "NOT_SUPPORTED"
    target_removal_date: "2025-08-31"
  }]; // The type of the experiment
  oneof experiment {
    option (.wix.api.aligned_with_enum).field = "experiment_type";
    GradualRollout gradual_rollout_options = 8 [deprecated = true, (.wix.api.field_deprecated) = {
      replaced_by: "CreateComponent"
      target_removal_date: "2025-08-31"
    }]; // Gradually exposing a component to users
    GradualUpdate gradual_update_options = 9 [deprecated = true, (.wix.api.field_deprecated) = {
      replaced_by: "UpdateComponent"
      target_removal_date: "2025-08-31"
    }]; // Gradually updating a component to users
    GradualDelete gradual_delete_options = 10 [deprecated = true, (.wix.api.field_deprecated) = {
      replaced_by: "DeleteComponent"
      target_removal_date: "2025-08-31"
    }]; // Gradually deleting a component to users
  }
  ExperimentActionType experiment_action_type = 11; // The type of the experiment
  oneof experiment_action {
    option (.wix.api.aligned_with_enum).field = "experiment_action_type";
    CreateComponent create_component_options = 12; // Experiment result is to create a component
    UpdateComponent update_component_options = 13; // Experiment result is to update specific fields in the component
    DeleteComponent delete_component_options = 14; // Experiment result is to delete a component
  }
}

enum ExperimentType {
  UNKNOWN_EXPERIMENT = 0;
  GRADUAL_ROLLOUT = 1;
  GRADUAL_UPDATE = 2;
  GRADUAL_DELETE = 3;
}

enum ExperimentActionType {
  UNKNOWN_ACTION = 0;
  CREATE_COMPONENT = 1;
  UPDATE_COMPONENT = 2;
  DELETE_COMPONENT = 3;
}


message GradualRollout {
  int32 experiment_version = 1 [(.wix.api.min) = 0]; // Version from which the experiment should decide whether to expose it to users when `conduct(spec).contains(variant_value)`
}

message GradualUpdate {
  int32 experiment_version = 1 [(.wix.api.min) = 0]; // Version from which the experiment should decide whether to expose it to users when `conduct(spec).contains(variant_value)`
  int32 fallback_version = 2 [(.wix.api.min) = 0]; // Version to expose when `!conduct(spec).contains(variant_value)`
}

message GradualDelete {
  int32 experiment_version = 1 [(.wix.api.min) = 0]; // Version from which the experiment should decide whether to expose it to users when `!conduct(spec).contains(variant_value)`
}

message CreateComponent {
  int32 experiment_version = 1 [(.wix.api.min) = 0]; // Version from which the experiment should decide whether to expose it to users when `conduct(spec).contains(variant_value)`
}

message UpdateComponent {
  int32 experiment_version = 1 [(.wix.api.min) = 0]; // Version from which the experiment should decide whether to expose it to users when `conduct(spec).contains(variant_value)`
  repeated string paths = 2 [(.wix.api.maxSize) = 100]; // Which fields to conduct the experiments on
  com.wixpress.appservice.api.ComponentData data = 3; // The source data which the experiment will take the data from
}

message DeleteComponent {
  int32 experiment_version = 1 [(.wix.api.min) = 0]; // Version from which the experiment should decide whether to expose it to users when `!conduct(spec).contains(variant_value)`
}
