// Copyright 2023-2025 Buf Technologies, Inc.
//
// 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 = "proto3";

package tests.example.v1;

import "buf/validate/validate.proto";
import "google/protobuf/timestamp.proto";

message MultipleValidations {
  string title = 1 [(buf.validate.field).string.prefix = "foo"];
  string name = 2 [(buf.validate.field).string.min_len = 5];
}

message DoubleFinite {
  double val = 1 [(buf.validate.field).double.finite = true];
}

message SFixed64ExLTGT {
  sfixed64 val = 1 [(buf.validate.field).sfixed64 = {
    lt: 0
    gt: 10
  }];
}

message TestOneofMsg {
  bool val = 1 [(buf.validate.field).bool.const = true];
}

message Oneof {
  oneof o {
    string x = 1 [(buf.validate.field).string.prefix = "foo"];
    int32 y = 2 [(buf.validate.field).int32.gt = 0];
    TestOneofMsg z = 3;
  }
}

message ProtovalidateOneof {
  string a = 1;
  string b = 2;
  bool unrelated = 3;
  option (buf.validate.message).oneof = {
    fields: [
      "a",
      "b"
    ]
  };
}

message ProtovalidateOneofRequired {
  string a = 1;
  string b = 2;
  bool unrelated = 3;
  option (buf.validate.message).oneof = {
    fields: [
      "a",
      "b"
    ]
    required: true
  };
}

message ProtovalidateOneofUnknownFieldName {
  string a = 1;
  string b = 2;
  bool unrelated = 3;
  option (buf.validate.message).oneof = {
    fields: [
      "a",
      "b",
      "xxx"
    ]
  };
}

message TimestampGTNow {
  google.protobuf.Timestamp val = 1 [(buf.validate.field).timestamp.gt_now = true];
}

message MapMinMax {
  map<string, bool> val = 1 [(buf.validate.field).map = {
    min_pairs: 2
    max_pairs: 4
  }];
}

message MapKeys {
  map<sint64, string> val = 1 [(buf.validate.field).map.keys.sint64.lt = 0];
}

message Embed {
  int64 val = 1 [(buf.validate.field).int64.gt = 0];
}

message RepeatedEmbedSkip {
  repeated Embed val = 1 [(buf.validate.field).repeated.items.ignore = IGNORE_ALWAYS];
}

message InvalidRESyntax {
  string value = 1 [(buf.validate.field).string.pattern = "^\\z"];
}

// via #353.

message ConcatenatedValues {
  option (buf.validate.message).cel = {
    id: "globally_unique_names"
    message: "all values in bar and baz must be globally unique"
    expression: "(this.bar + this.baz).unique()"
  };

  repeated string bar = 1;
  repeated string baz = 2;
}
