syntax = "proto3";
// flynt-disable package-matches-structure
package com.wixpress.appservice.api.upstream.wix.segments.spi.v2;
option java_package = "com.wixpress.appservice.api.upstream.wix.segments.spi.v2";

import "wix/api/annotations.proto";
import "wix/api/validations.proto";
import "components_catalog_data/contacts_segments_v2_filter_provider/com/wixpress/appservice/api/upstream/wix/segments/v2/common/segments_common.proto";
import "components_catalog_data/contacts_segments_v2_filter_provider/com/wixpress/appservice/api/upstream/wix/segments/spi/v2/time_constraint_configuration.proto";

// Capability for supported filters
message FilteringCapability {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.FilteringCapability";
  // Name of the attribute that can be filtered (e.g., "email", "age", "last_purchase_date").
  string attribute_name = 1 [(.wix.api.maxLength) = 30];

  // Human-readable display name for the attribute shown in UI.
  // should be translated to the user's language, as described by the language header
  // todo https://github.com/wix-private/server-infra/blob/7e756ad50d208ac37dd3678cbd4425c17bdd6da7/framework/loom-prime/examples/prime-spi/readme.md#language-aspect
  string display_name = 2 [(.wix.api.maxLength) = 50];

  // Optional description explaining what this attribute represents.
  // should be translated to the user's language, as described by the language header
  // todo https://github.com/wix-private/server-infra/blob/7e756ad50d208ac37dd3678cbd4425c17bdd6da7/framework/loom-prime/examples/prime-spi/readme.md#language-aspect
  string description = 3 [(.wix.api.maxLength) = 200];

  // operators and parameters supported for this attribute.
  repeated OperatorConfiguration operator_configurations = 4 [(.wix.api.maxSize) = 20];

  // Optional time constraints that can be applied to this filter.
  repeated com.wixpress.appservice.api.upstream.wix.segments.spi.v2.TimeConstraintConfiguration supported_time_constraints = 5 [(.wix.api.maxSize) = 10];
}

// Operator definition with its required parameters.
message OperatorConfiguration {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.OperatorConfiguration";
  // List of operators supported for this configuration (e.g., EQ, GT, IN).
  repeated com.wixpress.appservice.api.upstream.wix.segments.v2.common.OperatorEnum.Operator supported_operators = 1 [(.wix.api.maxSize) = 10, (.wix.api.minSize) = 1];
  // Parameters required for this operator (e.g., multiple parameters for "BETWEEN").
  repeated Parameter parameters = 2 [(.wix.api.maxSize) = 5];
}

// Parameter definition for parameterized filters
message Parameter {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.Parameter";
  // Name or identifier of the parameter.
  string name = 1 [(.wix.api.maxLength) = 30];

  // Human-readable display name for the parameter shown in UI.
  // should be translated to the user's language, as described by the language header
  // todo https://github.com/wix-private/server-infra/blob/7e756ad50d208ac37dd3678cbd4425c17bdd6da7/framework/loom-prime/examples/prime-spi/readme.md#language-aspect
  string display_name = 2 [(.wix.api.maxLength) = 30];
  // Data type of the parameter value.
  ParameterType type = 3;
  // Whether this parameter is required for the operation.
  bool mandatory = 4;

  // Whether this parameter can accept multiple values (e.g., for IN operator).
  bool repeated = 5;

  // The primary mode determining how values are defined.
  // This drives the 'value_definition_details' oneof.
  FilterValueDefinitionMode definition_mode = 6;

  oneof value_definition_details {
    option (.wix.api.aligned_with_enum).field = "definition_mode";
    // For STRING_LIST
    StringListOptions string_list_options = 7;
    // For INT64_LIST
    IntListOptions int_list_options = 8;
    // For DECIMAL_LIST
    DecimalListOptions decimal_list_options = 9;
    // For BOOL_LIST
    BoolListOptions bool_list_options = 10;
    // For CURRENCY_CODE_LIST
    CurrencyCodeListOptions currency_list_options = 11;
    // For COUNTRY_SUBDIVISION_LIST
    CountrySubdivisionListOptions country_subdivision_list_options = 12;
    // For LANGUAGE_LIST
    LanguageTagListOptions language_tag_list_options = 13;
    // For ITEM_SELECTION
    ItemSelectionOptions item_selection_options = 14;
  }
}

message StringListOptions {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.StringListOptions";
  // List of predefined string values that can be selected.
  repeated string values = 1 [(.wix.api.maxSize) = 20, (.wix.api.maxLength) = 50];
}

message IntListOptions {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.IntListOptions";
  // List of predefined integer values that can be selected.
  repeated int64 values = 1 [(.wix.api.maxSize) = 20];
}

message BoolListOptions {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.BoolListOptions";
  // List of predefined boolean values that can be selected.
  repeated bool values = 1 [(.wix.api.maxSize) = 2];
}

message DecimalListOptions {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.DecimalListOptions";
  // List of predefined decimal values that can be selected.
  // Uses string representation of decimals for accuracy.
  repeated string values = 1 [(.wix.api.maxSize) = 20, (.wix.api.maxLength) = 50];
}

message CurrencyCodeListOptions {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.CurrencyCodeListOptions";
  // List of predefined currency codes that can be selected.
  // ISO 4217 alphabetic codes (e.g., "USD", "EUR", "GBP").
  repeated string values = 1 [(.wix.api.maxSize) = 20, (.wix.api.format) = CURRENCY];
}

message CountrySubdivisionListOptions {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.CountrySubdivisionListOptions";
  // List of predefined country subdivision codes that can be selected.
  // ISO 3166-2 codes for subdivisions
  repeated string values = 1 [(.wix.api.maxSize) = 20, (.wix.api.format) = SUBDIVISION];
}

message LanguageTagListOptions {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.LanguageTagListOptions";
  // List of predefined language codes that can be selected.
  // ISO 639-1 language codes (e.g., "en", "es", "fr").
  repeated string values = 1 [(.wix.api.maxSize) = 20, (.wix.api.format) = LANGUAGE_TAG];
}

message ItemSelectionOptions {
    option (.wix.api.decomposite_of) = "wix.segments.spi.v2.ItemSelectionOptions";
  // TODO https://wix.slack.com/archives/C02H9KH8WG6/p1749479838660939
  string entity_reference = 1 [(.wix.api.maxLength) = 200];
}

// Supported parameter data types
enum ParameterType {
  UNKNOWN_PARAMETER_TYPE = 0 [(.wix.api.enum_maturity) = NOT_IMPLEMENTED];
  STRING = 1;
  INT = 2;
  DECIMAL = 3;
  BOOL = 4;
  // ISO 4217 currency codes
  CURRENCY = 5;
  // ISO 3166-2 codes for subdivisions
  COUNTRY_SUBDIVISION = 6;
  // ISO 639-1 language code
  LANGUAGE = 7;
}

// This new enum becomes the primary driver for the 'value_definition_details' oneof.
// It explicitly lists each way a filter parameter's values can be defined.
enum FilterValueDefinitionMode {
  UNKNOWN_FILTER_VALUE_DEFINITION_MODE = 0 [(.wix.api.enum_maturity) = NOT_IMPLEMENTED];

  // For "any value": Relies on 'FilterParameterDefinition.fundamental_data_type'.
  // No specific message will be set in the 'value_definition_details' oneof.
  ANY_VALUE_OF_SPECIFIED_TYPE = 1;
  ITEM_SELECTION = 2;

  STRING_LIST = 3;
  INT_LIST = 4;
  DECIMAL_LIST = 5;
  BOOL_LIST = 6;
  CURRENCY_LIST = 7;
  COUNTRY_SUBDIVISION_LIST = 8;
  LANGUAGE_TAG_LIST = 9;
}