syntax = "proto3";

package com.wixpress.appservice.api.upstream.wix.forms.templates.v2;
option java_package = "com.wixpress.appservice.api.upstream.wix.forms.templates.v2";

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

message Rule {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.Rule";
  reserved 2;
  // Id of the rule
  string id = 1 [(.wix.api.format) = GUID, (.wix.api.immutable) = true];

  // Rule on which item properties or layouts will be changed.
  ConditionNode expression = 5;

  // Form items with defined properties that will be
  // changed when given condition is resolved to true.
  repeated FormOverride overrides = 3 [(.wix.api.maxSize) = 500];

  // Name of the rule
  google.protobuf.StringValue name = 4[(.wix.api.maxLength) = 200];

  message FormOverride {
        option (.wix.api.decomposite_of) = "wix.forms.templates.v2.Rule.FormOverride";
    // Override entity type.
    OverrideEntityTypeEnum.OverrideEntityType entity_type = 1 [(.wix.api.immutable) = true];

    oneof entity_type_options {
      option (.wix.api.aligned_with_enum).field = "entity_type";
      // Field override properties.
      FieldOverride field_options = 2;
    }

    message OverrideEntityTypeEnum {
        option (.wix.api.decomposite_of) = "wix.forms.templates.v2.Rule.OverrideEntityTypeEnum";
      enum OverrideEntityType {
        UNKNOWN = 0;
        FIELD = 1;
      }
    }

    message FieldOverride {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.FieldOverride";
      // Overridden entity id
      string field_id = 1 [(.wix.api.immutable) = true, (.wix.api.format) = GUID];
      // Form entity properties path with new value, that will be changed on condition.
      ChangeablePropertyEnum.ChangeableProperty property_type = 2;
      oneof property_type_options{
        option (.wix.api.aligned_with_enum).field = "property_type";
        //Required property overrides
        RequiredOptions required_options = 3;
        //Hidden property overrides
        HiddenOptions hidden_options = 4;
        //Allowed values property overrides
        AllowedValuesOptions allowed_values_options = 5;
      }

      message RequiredOptions {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.RequiredOptions";
        // Value of required property
        bool value = 1;
      }

      message HiddenOptions {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.HiddenOptions";
        // Value of hidden property
        bool value = 1;
      }

      message AllowedValuesOptions {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.AllowedValuesOptions";
        // Allowed values
        repeated string value = 1 [(.wix.api.maxSize) = 300, (.wix.api.maxLength) = 200];
      }
    }
  }
}

message Condition {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.Condition";
  // The property name to be evaluated, supports dot notation for nested properties.
  string fact = 1 [(.wix.api.maxLength) = 100];
  // The operator to use for comparison.
  OperatorEnum.Operator operator = 2;
  // The value to compare against.
  string value = 3 [(.wix.api.maxLength) = 500];
}


message ConditionNode {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.ConditionNode";
  oneof node {
    // A compound condition that requires all conditions to be true.
    AndCondition and = 1;
    // A compound condition that requires at least one condition to be true.
    OrCondition or = 2;
    // A single condition in the rule.
    Condition condition = 3;
  }
}

message AndCondition {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.AndCondition";
  // The list of conditions that must all be true.
  repeated ConditionNode conditions = 1 [(.wix.api.minSize) = 1, (.wix.api.maxSize) = 100];
}

message OrCondition {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.OrCondition";
  // The list of conditions where at least one must be true.
  repeated ConditionNode conditions = 1  [(.wix.api.minSize) = 1, (.wix.api.maxSize) = 100];
}

message OperatorEnum {
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.OperatorEnum";
  enum Operator {
    UNKNOWN = 0;
    EQUAL = 1;
    NOT_EQUAL = 2;
    EMPTY = 3;
    NOT_EMPTY = 4;
    CONTAINS = 5;
    NOT_CONTAINS = 6;
    LESS_THAN = 7;
    LESS_THAN_OR_EQUALS = 8;
    GREATER_THAN = 9;
    GREATER_THAN_OR_EQUALS = 10;
    BEFORE = 11;
    BEFORE_OR_EQUAL = 12;
    AFTER = 13;
    AFTER_OR_EQUAL = 14;
    BETWEEN = 15;
    ANY = 16;
    ARRAY_EQUAL = 17;
    ARRAY_NOT_EQUAL = 18;
    CHECKED = 19;
    NOT_CHECKED = 20;
    IN = 21;
    NOT_IN = 22;
    IS_DATE_OLDER_THAN = 23;
    IS_DATE_OLDER_THAN_OR_EQUAL = 24;
    IS_DATE_NEWER_THAN = 25;
    IS_DATE_NEWER_THAN_OR_EQUAL = 26;
  }
}

message ChangeablePropertyEnum{
    option (.wix.api.decomposite_of) = "wix.forms.templates.v2.ChangeablePropertyEnum";
  // Enum for different types of changeable properties.
  enum ChangeableProperty {
    // Unknown property type.
    UNKNOWN = 0;
    // Required property type.
    REQUIRED = 1;
    // Hidden property type.
    HIDDEN = 2;
    // Allowed values property type.
    ALLOWED_VALUES = 3;
  }
}


