syntax = "proto2";

extend google.protobuf.FieldOptions {
  optional bool weak = 20004;

  optional uint64 uint64 = 20011;

  optional uint32 uint32 = 20010;

  optional int32 true = 20033;

  optional bool to = 20032;

  optional bool syntax = 20001;

  optional string string = 20006;

  optional sint64 sint64 = 20013;

  optional sint32 sint32 = 20012;

  optional sfixed64 sfixed64 = 20017;

  optional sfixed32 sfixed32 = 20016;

  optional bool service = 20026;

  optional bool rpc = 20027;

  optional bool reserved = 20031;

  optional bool required = 20023;

  optional bool repeated = 20022;

  optional bool public = 20003;

  optional bool package = 20005;

  optional bool optional = 20021;

  optional bool option = 20028;

  optional bool message = 20024;

  optional int64 int64 = 20009;

  optional int32 int32 = 20008;

  optional bool import = 20002;

  optional float float = 20019;

  optional fixed64 fixed64 = 20015;

  optional fixed32 fixed32 = 20014;

  optional int32 false = 20034;

  optional bool extensions = 20030;

  optional bool extend = 20029;

  optional bool enum = 20025;

  optional double double = 20020;

  optional int32 default = 20035;

  optional bytes bytes = 20007;

  optional KeywordCollisions boom = 20036;

  optional bool bool = 20018;
}

extend google.protobuf.MethodOptions {
  optional Validator validator = 12345;
}

extend google.protobuf.FieldOptions {
  optional Rule rules = 1234;
}

extend google.protobuf.MessageOptions {
  repeated Test rept = 20002;

  optional MessageWithMap map_vals = 20030;

  optional Test.Nested._NestedNested.EEE eee = 20010;

  optional Another a = 20020;
}

extend google.protobuf.ExtensionRangeOptions {
  optional string label = 20000;
}

service TestTestService {
  rpc UserAuth ( Test ) returns ( Test ) {
    option (validator) = {
      authenticated: true
      permission: <
        action: LOGIN
        entity: "client"
      >
    };
  }

  rpc Get ( Test ) returns ( Test ) {
    option (validator) = {
      authenticated: true
      permission: <
        action: READ
        entity: "user"
      >
    };
  }
}

enum EnumWithReservations {
  Z = 4;

  Y = 3;

  X = 2;

  reserved "C", "B", "A";

  reserved 1000 to max, 18, 12 to 15, 5 to 10, -2 to 1, -5 to -3;
}

message Validator {
  enum Action {
    WRITE = 2;

    READ = 1;

    LOGIN = 0;
  }

  message Permission {
    optional string entity = 2;

    optional Action action = 1;
  }

  repeated Permission permission = 2;

  optional bool authenticated = 1;
}

message Test {
  extensions 20000 to max, 500 to 550, 300 to 350, 249 [(label) = "jazz"];

  extensions 100 to 200;

  message Nested {
    extend google.protobuf.MessageOptions {
      optional int32 fooblez = 20003;
    }

    message _NestedNested {
      extend Test {
        optional string _garblez = 100;
      }

      enum EEE {
        V6 = 6;

        V5 = 5;

        V4 = 4;

        V3 = 3;

        V2 = 2;

        V1 = 1;

        OK = 0;
      }

      message NestedNestedNested {
        optional Test Test = 1;

        option (rept) = {
          foo: "hoo"
          [foo.bar.Test.Nested._NestedNested._garblez]: "spoo"
        };
      }

      option (rept) = {
        foo: "goo"
        [foo.bar.Test.Nested._NestedNested._garblez]: "boo"
      };

      option (fooblez) = 10101;
    }
  }

  optional Simple s = 3;

  repeated Simple r = 4;

  map<string, int32> m = 5;

  optional string foo = 1 [json_name = "|foo|"];

  optional bytes b = 6 [default = "\000\001\002\003\004\005\006\007fubar!"];

  repeated int32 array = 2;
}

message Simple {
  optional string name = 1;

  optional uint64 id = 2;

  optional bytes _extra = 3; // default JSON name will be capitalized

  repeated bool _ = 4; // default JSON name will be empty(!)
}

message Rule {
  message StringRule {
    optional string pattern = 1;

    optional int32 min_len = 3;

    optional int32 max_len = 4;

    optional bool allow_empty = 2;
  }

  message RepeatedRule {
    optional int32 min_items = 2;

    optional int32 max_items = 3;

    optional Rule items = 4;

    optional bool allow_empty = 1;
  }

  message IntRule {
    optional int64 min_val = 1;

    optional uint64 max_val = 2;
  }

  oneof rule {
    StringRule string = 1;

    RepeatedRule repeated = 2;

    IntRule int = 3;

    group FloatRule = 4 {
      optional double min_val = 1;

      optional double max_val = 2;
    }
  }
}

message MessageWithReservations {
  reserved "C", "B", "A";

  reserved 1000 to max, 18, 12 to 15, 5 to 10;
}

message MessageWithMap {

  map<string, Simple> vals = 1;
}

// tests cases where field names collide with keywords

message KeywordCollisions {
  optional bool weak = 4;

  optional uint64 uint64 = 11;

  optional uint32 uint32 = 10;

  optional int32 true = 33;

  optional bool to = 32;

  optional bool syntax = 1;

  optional string string = 6;

  optional sint64 sint64 = 13;

  optional sint32 sint32 = 12;

  optional sfixed64 sfixed64 = 17;

  optional sfixed32 sfixed32 = 16;

  optional bool service = 26;

  optional bool rpc = 27;

  optional bool reserved = 31;

  optional bool required = 23;

  optional bool repeated = 22;

  optional bool public = 3;

  optional bool package = 5;

  optional bool optional = 21;

  optional bool option = 28;

  optional bool message = 24;

  optional int64 int64 = 9;

  optional int32 int32 = 8;

  optional bool import = 2;

  optional float float = 19;

  optional fixed64 fixed64 = 15;

  optional fixed32 fixed32 = 14;

  optional int32 false = 34;

  optional bool extensions = 30;

  optional bool extend = 29;

  optional bool enum = 25;

  optional double double = 20;

  optional int32 default = 35;

  optional bytes bytes = 7;

  optional bool bool = 18;
}

message KeywordCollisionOptions {
  optional string name = 2 [
    (boom) = {
      syntax: true
      import: true
      public: true
      weak: true
      package: true
      string: "string"
      bytes: "bytes"
      int32: 32
      int64: 64
      uint32: 3200
      uint64: 6400
      sint32: -32
      sint64: -64
      fixed32: 3232
      fixed64: 6464
      sfixed32: -3232
      sfixed64: -6464
      bool: true
      float: 3.14
      double: 3.14159
      optional: true
      repeated: true
      required: true
      message: true
      enum: true
      service: true
      rpc: true
      option: true
      extend: true
      extensions: true
      reserved: true
      to: true
      true: 111
      false: -111
      default: 222
    }
  ];

  optional uint64 id = 1 [
    (weak) = true,
    (uint64) = 6400,
    (uint32) = 3200,
    (true) = 111,
    (to) = true,
    (syntax) = true,
    (string) = "string",
    (sint64) = -64,
    (sint32) = -32,
    (sfixed64) = -6464,
    (sfixed32) = -3232,
    (service) = true,
    (rpc) = true,
    (reserved) = true,
    (required) = true,
    (repeated) = true,
    (public) = true,
    (package) = true,
    (optional) = true,
    (option) = true,
    (message) = true,
    (int64) = 64,
    (int32) = 32,
    (import) = true,
    (float) = 3.140000,
    (fixed64) = 6464,
    (fixed32) = 3232,
    (false) = -111,
    (extensions) = true,
    (extend) = true,
    (enum) = true,
    (double) = 3.141590,
    (default) = 222,
    (bytes) = "bytes",
    (bool) = true
  ];
}

message IsAuthorizedReq {
  repeated string subjects = 1 [
    (rules) = {
      repeated: <
        min_items: 1
        items: <
          string: <
            pattern: "^(?:(?:team:(?:local|ldap))|user):[[:alnum:]_-]+$"
          >
        >
      >
    }
  ];
}

message Another {
  optional Test test = 1;

  optional Test.Nested._NestedNested.EEE fff = 2 [default = V1];

  option (rept) = {
    foo: "abc"
    array: 1
    array: 2
    array: 3
    s: <
      name: "foo"
      id: 123
    >
    r: <
      name: "f"
    >
    r: <
      name: "s"
    >
    r: <
      id: 456
    >
  };
  option (rept) = {
    foo: "def"
    array: 3
    array: 2
    array: 1
    s: <
      name: "bar"
      id: 321
    >
    r: <
      name: "g"
    >
    r: <
      name: "s"
    >
  };
  option (rept) = { foo:"def" };

  option (map_vals) = {
    vals: <
      key: ""
      value: <
      >
    >
    vals: <
      key: "bar"
      value: <
        name: "baz"
      >
    >
    vals: <
      key: "foo"
      value: <
      >
    >
  }; // no key, no value

  option (eee) = V1;

  option (a) = {
    test: <
      foo: "m&m"
      array: 1
      array: 2
      s: <
        name: "yolo"
        id: 98765
      >
      m: <
        key: "bar"
        value: 200
      >
      m: <
        key: "foo"
        value: 100
      >
      [foo.bar.Test.Nested._NestedNested._garblez]: "whoah!"
    >
    fff: OK
  };
}

option go_package = "github.com/jhump/protoreflect/internal/testprotos";

import "google/protobuf/descriptor.proto";

package foo.bar;
