//
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

syntax = "proto2";

package zetasql;

import "zetasql/public/builtin_function.proto";
import "zetasql/public/options.proto";
import "zetasql/public/type.proto";
import "zetasql/resolved_ast/resolved_node_kind.proto";

option java_package = "com.google.zetasql";
option java_outer_classname = "ZetaSQLOptionsProto";

// Specify what built-in functions should be load.
// Used for getting built-in functions through local server.
message ZetaSQLBuiltinFunctionOptionsProto {
  optional LanguageOptionsProto language_options = 1;
  repeated FunctionSignatureId include_function_ids = 2;
  repeated FunctionSignatureId exclude_function_ids = 3;
  repeated EnabledRewriteProto enabled_rewrites_map_entry = 4;
}

message EnabledRewriteProto {
  optional FunctionSignatureId key = 1;
  optional bool value = 2;
}

// Serialized form of LanguageOptions.
message LanguageOptionsProto {
  reserved 1;  // optional TimestampMode timestamp_mode = 1;
  optional NameResolutionMode name_resolution_mode = 2;
  optional ProductMode product_mode = 3;
  optional bool error_on_deprecated_syntax = 4;
  repeated LanguageFeature enabled_language_features = 5;
  repeated ResolvedNodeKind supported_statement_kinds = 6;
  repeated string supported_generic_entity_types = 7;
  repeated string reserved_keywords = 8;
  repeated string supported_generic_sub_entity_types = 9;
}

// Serialized form of AllowedHintsAndOptions.
message AllowedHintsAndOptionsProto {
  message HintProto {
    optional string qualifier = 1;
    optional string name = 2;
    optional TypeProto type = 3;
    optional bool allow_unqualified = 4;
  }
  message OptionProto {
    optional string name = 1;
    optional TypeProto type = 2;
    enum ResolvingKind {
      // Legacy kind - option is either constant or an identifier resolved
      // without any given name scope.
      CONSTANT_OR_EMPTY_NAME_SCOPE_IDENTIFIER = 0;
      // Option is an identifier resolved against FROM name scope.
      // See: (broken link).
      FROM_NAME_SCOPE_IDENTIFIER = 1;
    }
    optional ResolvingKind resolving_kind = 3;
  }

  optional bool disallow_unknown_options = 1;
  repeated string disallow_unknown_hints_with_qualifier = 2;
  repeated HintProto hint = 3;
  repeated OptionProto option = 4;
  repeated OptionProto anonymization_option = 5;
  repeated OptionProto differential_privacy_option = 6;
  optional bool disallow_duplicate_option_names = 7;
}

// Serialized form of AnalyzerOptions.
// next id: 29
message AnalyzerOptionsProto {
  message QueryParameterProto {
    optional string name = 1;
    optional TypeProto type = 2;
  }

  message SystemVariableProto {
    repeated string name_path = 1;
    optional TypeProto type = 2;
  }

  optional LanguageOptionsProto language_options = 1;
  repeated QueryParameterProto query_parameters = 2;
  repeated TypeProto positional_query_parameters = 12;
  repeated QueryParameterProto expression_columns = 3;
  optional QueryParameterProto in_scope_expression_column = 4;
  repeated QueryParameterProto ddl_pseudo_columns = 15;
  // base::SequenceNumber does not support getting and setting the current
  // value, so it is not serializable. Reserving tag number 5 in case we want
  // to support it in some other way later.
  optional ErrorMessageMode error_message_mode = 6;
  // In the form that can be parsed by C++ absl::LoadTimeZone().
  optional string default_timezone = 7;
  reserved 8;
  reserved 22;
  optional bool create_new_column_for_each_projected_output = 20;
  optional bool prune_unused_columns = 9;
  optional bool allow_undeclared_parameters = 10;
  optional ParameterMode parameter_mode = 13;
  optional AllowedHintsAndOptionsProto allowed_hints_and_options = 11;
  optional StatementContext statement_context = 14;
  reserved 16;  // optional bool strict_validation_on_column_replacements = 16;
  optional bool preserve_column_aliases = 17;
  repeated SystemVariableProto system_variables = 18;
  repeated TypeProto target_column_types = 19;
  repeated ResolvedASTRewrite enabled_rewrites = 21;
  optional ParseLocationRecordType parse_location_record_type = 23;
  optional bool preserve_unnecessary_cast = 24;
  optional bool show_function_signature_mismatch_details = 27;
  optional string default_anon_function_report_format = 25;
  optional int64 default_anon_kappa_value = 26;
  optional RewriteOptions rewrite_options = 28;
}
