syntax = "proto2";
package otsprotocol;

enum VariantType {
    VT_INTEGER = 0;
    VT_DOUBLE = 1;
    //VT_BOOLEAN = 2;
    VT_STRING = 3;
    VT_NULL = 6;
    VT_BLOB = 7;
}

message ValueTransferRule {
    required string regex = 1;
    optional VariantType cast_type = 2;
}

enum FilterType {
    FT_SINGLE_COLUMN_VALUE = 1;
    FT_COMPOSITE_COLUMN_VALUE = 2;
    FT_COLUMN_PAGINATION = 3;
}

enum ComparatorType {
    CT_EQUAL                    = 1;
    CT_NOT_EQUAL                = 2;
    CT_GREATER_THAN             = 3;
    CT_GREATER_EQUAL            = 4;
    CT_LESS_THAN                = 5;
    CT_LESS_EQUAL               = 6;
}

message SingleColumnValueFilter {
    required ComparatorType comparator     = 1;
    required string column_name        = 2;
    required bytes column_value        = 3; // Serialized SQLVariant
    required bool filter_if_missing        = 4;
    required bool latest_version_only      = 5;
    optional ValueTransferRule value_trans_rule = 6;
}

enum LogicalOperator {
    LO_NOT                      = 1;
    LO_AND                      = 2;
    LO_OR                       = 3;
}

message CompositeColumnValueFilter {
    required LogicalOperator combinator    = 1;
    repeated Filter sub_filters            = 2;
}

message ColumnPaginationFilter {
    required int32 offset = 1;
    required int32 limit = 2;
}

message Filter {
    required FilterType type    = 1;
    required bytes filter       = 2;  // Serialized string of filter of the type
}
