//
// 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.
//

// Common types for serializing the ResolvedAST
syntax = "proto2";

package zetasql;

import "zetasql/public/annotation.proto";
import "zetasql/public/parse_location_range.proto";
import "zetasql/public/type.proto";
import "zetasql/public/value.proto";

option java_package = "com.google.zetasql";
option java_multiple_files = true;
option java_outer_classname = "ZetaSQLSerialization";

// Proto representation of zetasql::ResolvedColumn.
message ResolvedColumnProto {
  optional int64 column_id = 1;
  optional string table_name = 2;
  optional string name = 3;
  optional TypeProto type = 4;
  optional AnnotationMapProto annotation_map = 5;
}

message ValueWithTypeProto {
  optional TypeProto type = 1;
  optional ValueProto value = 2;
}

// Reference to a table.
message TableRefProto {
  optional string name = 1;
  optional int64 serialization_id = 2;
  optional string full_name = 3;
}

// Reference to a model.
message ModelRefProto {
  optional string name = 1;
  optional int64 serialization_id = 2;
  optional string full_name = 3;
}

// Reference to a connection
message ConnectionRefProto {
  optional string name = 1;
  optional string full_name = 3;
}

// Reference to a sequence.
message SequenceRefProto {
  optional string name = 1;
  optional string full_name = 2;
}

// Reference to a named constant.
message ConstantRefProto {
  // Full name of the function, e.g., catalog1.catalog2.Constant.
  optional string name = 1;
}

// Reference to a function.
message FunctionRefProto {
  // TODO: Optimize this by generating unique serialization IDs.
  // Full name of the function, e.g., group:pathname.
  optional string name = 1;
}

// Reference to a table-valued function.
message TableValuedFunctionRefProto {
  // Full name of the function, e.g., group:pathname.
  optional string name = 1;
}

message ResolvedNodeProto {
  // Parse location range if present in the ResolvedNode.
  optional ParseLocationRangeProto parse_location_range = 1;
}

// Reference to a proto field descriptor.
message FieldDescriptorRefProto {
  optional ProtoTypeProto containing_proto = 1;
  optional int32 number = 2;
}

// Reference to a proto2::OneofDescriptor, which describes the fields of an
// Oneof.
message OneofDescriptorRefProto {
  optional ProtoTypeProto containing_proto = 1;

  // 0-based offset which aligns with the order Oneof fields are defined in the
  // containing message.
  optional int32 index = 2;
}

message ProcedureRefProto {
  optional string name = 1;
}

// Proto representation of zetasql::ResolvedCollation.
message ResolvedCollationProto {
  optional string collation_name = 1;
  repeated ResolvedCollationProto child_list = 2;
}

message ColumnRefProto {
  optional TableRefProto table_ref = 1;
  optional string name = 2;
}
