syntax = "proto3";

package wix.dealerBackoffice.api.v1.upstream.wix.common;

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

option java_multiple_files = true;
option java_package = "com.wix.dealerBackoffice.api.v1.upstream.wix.common";

message Sorting {
    option (.wix.api.decomposite_of) = "wix.common.Sorting";
    option (.wix.api.decomposition_minimum_fields) = {
        field: "field_name"
        field: "order"
    };
    // Name of the field to sort by.
    string field_name = 1 [(.wix.api.maxLength) = 512];
    // Sort order.
    SortOrder order = 2;
    // When `field_name` is a property of repeated field that is marked as `MATCH_ITEMS` and sort should be done by
    // a specific element from a collection, filter can/should be provided to ensure correct sort value is picked.
    //
    // If multiple filters are provided, they are combined with AND operator.
    //
    // Example:
    // Given we have document like {"id": "1", "nestedField": [{"price": 10, "region": "EU"}, {"price": 20, "region": "US"}]}
    // and `nestedField` is marked as `MATCH_ITEMS`, to ensure that sorting is done by correct region, filter should be
    // { fieldName: "nestedField.price", "select_items_by": [{"nestedField.region": "US"}] }
    repeated google.protobuf.Struct select_items_by = 3 [(.wix.api.maxSize) = 10, (.wix.api.field_exposure) = PRIVATE];
}

enum SortOrder {
    ASC = 0;
    DESC = 1;
}