syntax = "proto3";

package dbag.energy.m7t.validation.v7;

import "google/protobuf/descriptor.proto";

option java_multiple_files = true;
option java_package = "com.deutscheboerse.energy.m7.api.common.v7";

// -------------------------------------------------------------------
// Extensions to FieldOptions for declarative validation rules.
// -------------------------------------------------------------------
extend google.protobuf.FieldOptions {
  // If true, this field must always be set in any message instance.
  //
  // Usage:
  //   string user_id = 1 [(mandatory) = true];
  bool mandatory = 50001;

  // Conditionally required based on another field value.
  //
  // When the sibling field named by `field_name` equals `field_value`,
  // the annotated field must be provided.
  //
  // Requirements:
  //  - `field_name` must refer to another field in the same message.
  //  - `field_value` is matched exactly. For enum fields, use the enum constant name as a string.
  //
  // Example:
  //   message Request {
  //     string action = 1;
  //     string delete_reason = 2 [
  //       (mandatoryIf) = {
  //         field_name:  "action"
  //         field_value: "DELETE"
  //       }
  //     ];
  //   }
  MandatoryIf mandatory_if = 50002;

  // Specifies the minimum length (in characters) of a string field.
  // Applied only when the field is provided otherwise ignored.
  // To apply this constraint in every instance, use it in conjunction with the `mandatory` option.
  //
  // Usage:
  //   string code = 2 [
  //     (min_length) = 3
  //   ];
  uint32 min_length = 50003;

  // Specifies the maximum length (in characters) of a string or field.
  // Applied only when the field is provided otherwise ignored.
  // To apply this constraint in every instance, use it in conjunction with the `mandatory` option.
  //
  // Usage:
  //   string comment = 3 [
  //     (max_length) = 256
  //   ];
  uint32 max_length = 50004;

  // Specifies the minimum length (in number of elements) of a repeated field.
  //
  // Usage:
  //   repeated string names = 2 [
  //     (min_occurrence) = 1
  //   ];
  uint32 min_occurrence = 50005;

  // Specifies the maximum length (in number of elements) of a repeated field.
  //
  // Usage:
  //   repeated string names = 2 [
  //     (max_occurrence) = 10
  //   ];
  uint32 max_occurrence = 50006;

  // Specifies that the annotated Timestamp field must be strictly later than the current time at validation.
  // Applied only when the field is provided otherwise ignored.
  // To apply this constraint in every instance, use it in conjunction with the `mandatory` option.
  //
  // Usage:
  //   google.protobuf.Timestamp start_time = 1 [
  //     (validate.rules).timestamp.gt_now = true
  //   ];
  bool gt_now = 50007;

  // Specifies the minimum allowed value of an integer field.
  // Applied only when the field is provided; to require it in every
  // instance, combine with the `mandatory` option.
  //
  // Usage:
  //   int32 age = 1 [(min_value) = 18];
  int32 min_value = 50008;
}

extend google.protobuf.OneofOptions {
  // Specifies that the annotated `oneof` group must have at least one field set at validation time.
  //
  // Usage:
  //   message ContactInfo {
  //     oneof primary {
  //       option (mandatory_oneof) = true;
  //       string email = 1;
  //       string phone = 2;
  //     }
  //   }
  bool mandatory_oneof = 51001;
}

message MandatoryIf {
  // Name of the sibling field whose value governs this requirement.
  string field_name  = 1;

  // The exact value of the other field that makes this field required.
  // - For string fields, match the literal text.
  // - For enum fields, use the enum constant name (not its numeric value).
  string field_value = 2;
}
