syntax = "proto3";

package wix.personalize.optimization_test.v1;
option java_package = "com.wixpress.personalize.optimization.test.v1";

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

/**
  A Test is a entity represents Petri test with the desire duration
  You can manage Petri tests and their results
 */
message Test {
  // flynt-disable missing-extensible
  // flynt-disable missing-taggable-annotation
  option (wix.api.entity) = {
    fqdn: "wix.personalize.optimization_test.v1.test"
    segment: PUBLIC
    app_def_id: "9e94fad7-8dc2-42c5-b7f7-5d57b88bca08"
    appendix_files: {
      type: DOCS_CONF,
      path: "appendices/docs"
    }
    query_options: {
      wql: {
        pattern: {
          operator: ALL_APPLICABLE_OPERATORS
          field: "id"
          field: "status"
          field: "experiment_id"
          sort: BOTH
        }
      }
    }
    domain_events_read_permission: "PERSONALIZE.READ_OPTIMIZE_TEST"
  };

  option (wix.api.domain_event) = {
    event_type: CREATED
    exposure: PUBLIC
    maturity: ALPHA
  };
  option (wix.api.domain_event) = {
    event_type: UPDATED
    exposure: PUBLIC
    maturity: ALPHA
  };
  option (wix.api.domain_event) = {
    event_type: DELETED
    exposure: PUBLIC
    maturity: ALPHA
  };

  // Test ID.
  google.protobuf.StringValue id = 1 [(wix.api.format) = GUID, (wix.api.readOnly) = true];

  /**
  Revision number, which increments by 1 each time the Test is updated.
  To prevent conflicting changes,
  the current revision must be passed when updating the Test.

  Ignored when creating a Test.
   */
  google.protobuf.Int64Value revision = 2 [(wix.api.readOnly) = true];

  // Date and time the Test was created.
  google.protobuf.Timestamp created_date = 3 [(wix.api.readOnly) = true];

  // Date and time the Test was last updated.
  google.protobuf.Timestamp updated_date = 4 [(wix.api.readOnly) = true];

  // The experiment id in Petri.
  google.protobuf.StringValue experiment_id = 5 [
    (wix.api.format) = GUID,
    deprecated = true,
    (.wix.api.field_deprecated) = {replaced_by: "ab_test_id", target_removal_date: "2025-12-30"}
  ];

  // The tested variants ids: A, B, C...
  repeated string variants = 6 [(wix.api.maxLength) = 1, (wix.api.minSize) = 2, (wix.api.maxSize) = 10];

  // The main kpis of the test
  repeated string kpis = 7 [(wix.api.format) = GUID, (wix.api.minSize) = 1, (wix.api.maxSize) = 10];

  // The status of the test in Petri.
  TestStatus status = 8;

  // The duration time of the test in days.
  google.protobuf.Int32Value duration_in_days = 9;

  // The test results from mvt_results wixer table.
  repeated MvtResults experiment_results = 10 [(wix.api.maxSize) = 10];

  // The exposure id in Data Platform.
  string exposure_id = 11 [(wix.api.format) = GUID];

  // The user email created the test.
  string created_by = 12 [(wix.api.format) = EMAIL];

  // The wixer id connects to the experiment.
  google.protobuf.StringValue wixer_id = 13 [(wix.api.maxLength) = 10];

  // The a/b test id in Petri.
  google.protobuf.StringValue ab_test_id = 14 [(wix.api.maxLength) = 60];

  // The ownership tag for the test. If not provided, defaults to "dealer-team".
  google.protobuf.StringValue ownership_tag = 15 [(wix.api.maxLength) = 100];

  enum TestStatus {
    UNKNOWN_TEST_STATUS = 0;
    NOT_STARTED = 1;
    ACTIVE = 2;
    ENDED = 3;
  }

  message MvtResults {
    // The current test date.
    google.protobuf.StringValue max_date = 1 [(wix.api.maxLength) = 20];

    // The results of the test in Wixer
    google.protobuf.Int32Value group_id = 2;

    // The variant name: Original/ A/ B/ C...
    google.protobuf.StringValue group_name = 3 [(wix.api.maxLength) = 15];

    // The number of exposed users to each variant.
    google.protobuf.Int32Value exposed = 4;

    // The percentage exposed (allocation) to each variant.
    google.protobuf.DoubleValue current_percentage = 5;

    // The name of the kpi
    google.protobuf.StringValue kpi_name = 6 [(wix.api.maxLength) = 100];

    // The kpi type: Main/ Mandatory
    google.protobuf.StringValue kpi_rank = 7 [(wix.api.maxLength) = 20];

    // Is the kpi is binary (true/false) or not.
    google.protobuf.BoolValue kpi_binary = 8;

    // For aggregated kpi -> total kpi sum
    google.protobuf.DoubleValue kpi_exposed_sum = 9;

    // For aggregated kpi -> avg kpi sum per user exposed (kpi_exposed_sum/exposed)
    google.protobuf.DoubleValue mean = 10;

    // For binary kpi -> % that made the kpi out of all exposed users
    google.protobuf.DoubleValue rate = 11;

    // For binary kpi -> number of users that made the kpi
    google.protobuf.DoubleValue kpi_after_exposure = 12;

    // For binary kpi -> % uplift of converted users / for aggregated kpi = % uplift of mean (sum per user exposed) [A vs A always be null]
    google.protobuf.DoubleValue uplift = 13;

    // Significant winner result (with 90% confidence) for each test (A vs B, A vs C...) [A vs A always be null]
    google.protobuf.StringValue winner = 14 [(wix.api.maxLength) = 15];

    // The id of the kpi
    google.protobuf.StringValue kpi_id = 15 [(wix.api.format) = GUID];
  }
}

message TestStopTask {
  // The test id to stop
  google.protobuf.StringValue test_id = 1 [(wix.api.format) = GUID];
}
