// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC.  All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

// LINT: ALLOW_GROUPS

syntax = "proto2";

package upb_test;

import "google/protobuf/test_messages_proto3.proto";

message TestExtensions {
  extensions 1000 to max
  [verification = UNVERIFIED];
  extend TestExtensions {
    optional int32 optional_int32_ext = 1000;
  }
  message Nested {
    extend TestExtensions {
      repeated int32 repeated_int32_ext = 1001;
    }
  }
}

extend TestExtensions {
  optional protobuf_test_messages.proto3.TestAllTypesProto3 optional_msg_ext =
      1002;
}

message TestMessageSet {
  option message_set_wire_format = true;

  extensions 4 to max
  [verification = UNVERIFIED];
}

message MessageSetMember {
  optional int32 optional_int32 = 1;
  extend TestMessageSet {
    optional MessageSetMember message_set_extension = 2000;
  }
  // Also extend a non-MessageSet with the same field number. This will allow us
  // to test parsing a normal extension into a MessageSet.
  extend TestExtensions {
    optional MessageSetMember doppelganger_message_set_extension = 2000;
  }
}

message FakeMessageSet {
  repeated group Item = 1 {
    optional int32 type_id = 2;
    optional bytes message = 3;
    optional int32 unknown_varint = 4;
    optional fixed32 unknown_fixed32 = 5;
    optional fixed64 unknown_fixed64 = 6;
    optional bytes unknown_bytes = 7;
    optional group UnknownGroup = 8 {}
  }
}

message Proto2EnumMessage {
  enum Proto2TestEnum {
    ZERO = 0;
    NEGATIVE = -1;
    SMALL = 15;
    LARGE = 12345;
  }

  optional Proto2TestEnum optional_enum = 1;
  repeated Proto2TestEnum repeated_enum = 2;
  repeated Proto2TestEnum packed_enum = 3 [packed = true];
}

// The same fields as Proto2EnumMessage, but with int32 fields so we can fake
// wire format.
message Proto2FakeEnumMessage {
  optional int32 optional_enum = 1;
  repeated int32 repeated_enum = 2;
  repeated int32 packed_enum = 3 [packed = true];
}

message EmptyMessage {}

message TestRequiredFields {
  required int32 required_int32 = 1;
  optional int32 optional_int32 = 2;
  required int64 required_int64 = 3;
  optional TestRequiredFields optional_message = 4;
  required EmptyMessage required_message = 5;
}

message SubMessageHasRequired {
  optional TestRequiredFields optional_message = 1;
}

message TestMaxRequiredFields {
  required int32 required_int32_1 = 1;
  required int32 required_int32_2 = 2;
  required int32 required_int32_3 = 3;
  required int32 required_int32_4 = 4;
  required int32 required_int32_5 = 5;
  required int32 required_int32_6 = 6;
  required int32 required_int32_7 = 7;
  required int32 required_int32_8 = 8;
  required int32 required_int32_9 = 9;
  required int32 required_int32_10 = 10;
  required int32 required_int32_11 = 11;
  required int32 required_int32_12 = 12;
  required int32 required_int32_13 = 13;
  required int32 required_int32_14 = 14;
  required int32 required_int32_15 = 15;
  required int32 required_int32_16 = 16;
  required int32 required_int32_17 = 17;
  required int32 required_int32_18 = 18;
  required int32 required_int32_19 = 19;
  required int32 required_int32_20 = 20;
  required int32 required_int32_21 = 21;
  required int32 required_int32_22 = 22;
  required int32 required_int32_23 = 23;
  required int32 required_int32_24 = 24;
  required int32 required_int32_25 = 25;
  required int32 required_int32_26 = 26;
  required int32 required_int32_27 = 27;
  required int32 required_int32_28 = 28;
  required int32 required_int32_29 = 29;
  required int32 required_int32_30 = 30;
  required int32 required_int32_31 = 31;
  required int32 required_int32_32 = 32;
  required int32 required_int32_33 = 33;
  required int32 required_int32_34 = 34;
  required int32 required_int32_35 = 35;
  required int32 required_int32_36 = 36;
  required int32 required_int32_37 = 37;
  required int32 required_int32_38 = 38;
  required int32 required_int32_39 = 39;
  required int32 required_int32_40 = 40;
  required int32 required_int32_41 = 41;
  required int32 required_int32_42 = 42;
  required int32 required_int32_43 = 43;
  required int32 required_int32_44 = 44;
  required int32 required_int32_45 = 45;
  required int32 required_int32_46 = 46;
  required int32 required_int32_47 = 47;
  required int32 required_int32_48 = 48;
  required int32 required_int32_49 = 49;
  required int32 required_int32_50 = 50;
  required int32 required_int32_51 = 51;
  required int32 required_int32_52 = 52;
  required int32 required_int32_53 = 53;
  required int32 required_int32_54 = 54;
  required int32 required_int32_55 = 55;
  required int32 required_int32_56 = 56;
  required int32 required_int32_57 = 57;
  required int32 required_int32_58 = 58;
  required int32 required_int32_59 = 59;
  required int32 required_int32_60 = 60;
  required int32 required_int32_61 = 61;
  required int32 required_int32_62 = 62;
}

message TestMapField {
  enum EnumMap {
    ZERO = 0;
    ONE = 1;
    TWO = 2;
  }
  map<int32, EnumMap> map_field = 1;
}

message TestMapFieldExtra {
  enum EnumMap {
    ZERO = 0;
    ONE = 1;
    TWO = 2;
    THREE = 3;
  }
  map<int32, EnumMap> map_field = 1;
}

message TestNameConflict {
  map<string, string> map_field = 1;
  optional bool clear_map_field = 2;
}

message TestFreeze {
  extensions 99 to max;

  optional string str = 1;
  optional TestFreeze msg = 2;

  map<int32, int32> map_int = 10;
  map<int32, TestFreeze> map_msg = 11;

  repeated int32 array_int = 20;
  repeated TestFreeze array_msg = 21;
}

extend TestFreeze {
  optional TestFreeze nest = 100;
}

extend TestFreeze {
  repeated Proto2EnumMessage rep_msg = 101;
}

message TestOneOfAlignment {
  optional fixed32 pad = 6;
  oneof value {
    string str = 10;
    fixed64 should_be_sixty_four_aligned = 11;
  }
}

message TestRepeatedMessageBig {
  repeated TestRepeatedMessageBig repeated_message = 1;
  repeated bytes repeated_bytes = 2;
}

message TestDuplicateFunctionNames {
  optional bool random = 6;
  oneof value {
    bytes body = 1;
    bool clear_body = 2;
  }
}
