// *** WARNING: this file was generated by pulumi-java-gen. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

package com.pulumi.kubernetes.apiextensions.v1.outputs;

import com.pulumi.core.annotations.CustomType;
import java.lang.String;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;

@CustomType
public final class ValidationRule {
    /**
     * @return fieldPath represents the field path returned when the validation fails. It must be a relative JSON path (i.e. with array notation) scoped to the location of this x-kubernetes-validations extension in the schema and refer to an existing field. e.g. when validation checks if a specific attribute `foo` under a map `testMap`, the fieldPath could be set to `.testMap.foo` If the validation checks two lists must have unique attributes, the fieldPath could be set to either of the list: e.g. `.testList` It does not support list numeric index. It supports child operation to refer to an existing field currently. Refer to [JSONPath support in Kubernetes](https://kubernetes.io/docs/reference/kubectl/jsonpath/) for more info. Numeric index of array is not supported. For field name which contains special characters, use `[&#39;specialName&#39;]` to refer the field name. e.g. for attribute `foo.34$` appears in a list `testList`, the fieldPath could be set to `.testList[&#39;foo.34$&#39;]`
     * 
     */
    private @Nullable String fieldPath;
    /**
     * @return Message represents the message displayed when validation fails. The message is required if the Rule contains line breaks. The message must not contain line breaks. If unset, the message is &#34;failed rule: {Rule}&#34;. e.g. &#34;must be a URL with the host matching spec.host&#34;
     * 
     */
    private @Nullable String message;
    /**
     * @return MessageExpression declares a CEL expression that evaluates to the validation failure message that is returned when this rule fails. Since messageExpression is used as a failure message, it must evaluate to a string. If both message and messageExpression are present on a rule, then messageExpression will be used if validation fails. If messageExpression results in a runtime error, the runtime error is logged, and the validation failure message is produced as if the messageExpression field were unset. If messageExpression evaluates to an empty string, a string with only spaces, or a string that contains line breaks, then the validation failure message will also be produced as if the messageExpression field were unset, and the fact that messageExpression produced an empty string/string with only spaces/string with line breaks will be logged. messageExpression has access to all the same variables as the rule; the only difference is the return type. Example: &#34;x must be less than max (&#34;+string(self.max)+&#34;)&#34;
     * 
     */
    private @Nullable String messageExpression;
    /**
     * @return reason provides a machine-readable validation failure reason that is returned to the caller when a request fails this validation rule. The HTTP status code returned to the caller will match the reason of the reason of the first failed validation rule. The currently supported reasons are: &#34;FieldValueInvalid&#34;, &#34;FieldValueForbidden&#34;, &#34;FieldValueRequired&#34;, &#34;FieldValueDuplicate&#34;. If not set, default to use &#34;FieldValueInvalid&#34;. All future added reasons must be accepted by clients when reading this value and unknown reasons should be treated as FieldValueInvalid.
     * 
     */
    private @Nullable String reason;
    /**
     * @return Rule represents the expression which will be evaluated by CEL. ref: https://github.com/google/cel-spec The Rule is scoped to the location of the x-kubernetes-validations extension in the schema. The `self` variable in the CEL expression is bound to the scoped value. Example: - Rule scoped to the root of a resource with a status subresource: {&#34;rule&#34;: &#34;self.status.actual &lt;= self.spec.maxDesired&#34;}
     * 
     * If the Rule is scoped to an object with properties, the accessible properties of the object are field selectable via `self.field` and field presence can be checked via `has(self.field)`. Null valued fields are treated as absent fields in CEL expressions. If the Rule is scoped to an object with additionalProperties (i.e. a map) the value of the map are accessible via `self[mapKey]`, map containment can be checked via `mapKey in self` and all entries of the map are accessible via CEL macros and functions such as `self.all(...)`. If the Rule is scoped to an array, the elements of the array are accessible via `self[i]` and also by macros and functions. If the Rule is scoped to a scalar, `self` is bound to the scalar value. Examples: - Rule scoped to a map of objects: {&#34;rule&#34;: &#34;self.components[&#39;Widget&#39;].priority &lt; 10&#34;} - Rule scoped to a list of integers: {&#34;rule&#34;: &#34;self.values.all(value, value &gt;= 0 &amp;&amp; value &lt; 100)&#34;} - Rule scoped to a string value: {&#34;rule&#34;: &#34;self.startsWith(&#39;kube&#39;)&#34;}
     * 
     * The `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from the root of the object and from any x-kubernetes-embedded-resource annotated objects. No other metadata properties are accessible.
     * 
     * Unknown data preserved in custom resources via x-kubernetes-preserve-unknown-fields is not accessible in CEL expressions. This includes: - Unknown field values that are preserved by object schemas with x-kubernetes-preserve-unknown-fields. - Object properties where the property schema is of an &#34;unknown type&#34;. An &#34;unknown type&#34; is recursively defined as:
     *   - A schema with no type and x-kubernetes-preserve-unknown-fields set to true
     *   - An array where the items schema is of an &#34;unknown type&#34;
     *   - An object where the additionalProperties schema is of an &#34;unknown type&#34;
     * 
     * Only property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible. Accessible property names are escaped according to the following rules when accessed in the expression: - &#39;__&#39; escapes to &#39;__underscores__&#39; - &#39;.&#39; escapes to &#39;__dot__&#39; - &#39;-&#39; escapes to &#39;__dash__&#39; - &#39;/&#39; escapes to &#39;__slash__&#39; - Property names that exactly match a CEL RESERVED keyword escape to &#39;__{keyword}__&#39;. The keywords are:
     * 	  &#34;true&#34;, &#34;false&#34;, &#34;null&#34;, &#34;in&#34;, &#34;as&#34;, &#34;break&#34;, &#34;const&#34;, &#34;continue&#34;, &#34;else&#34;, &#34;for&#34;, &#34;function&#34;, &#34;if&#34;,
     * 	  &#34;import&#34;, &#34;let&#34;, &#34;loop&#34;, &#34;package&#34;, &#34;namespace&#34;, &#34;return&#34;.
     * Examples:
     *   - Rule accessing a property named &#34;namespace&#34;: {&#34;rule&#34;: &#34;self.__namespace__ &gt; 0&#34;}
     *   - Rule accessing a property named &#34;x-prop&#34;: {&#34;rule&#34;: &#34;self.x__dash__prop &gt; 0&#34;}
     *   - Rule accessing a property named &#34;redact__d&#34;: {&#34;rule&#34;: &#34;self.redact__underscores__d &gt; 0&#34;}
     * 
     * Equality on arrays with x-kubernetes-list-type of &#39;set&#39; or &#39;map&#39; ignores element order, i.e. [1, 2] == [2, 1]. Concatenation on arrays with x-kubernetes-list-type use the semantics of the list type:
     *   - &#39;set&#39;: `X + Y` performs a union where the array positions of all elements in `X` are preserved and
     *     non-intersecting elements in `Y` are appended, retaining their partial order.
     *   - &#39;map&#39;: `X + Y` performs a merge where the array positions of all keys in `X` are preserved but the values
     *     are overwritten by values in `Y` when the key sets of `X` and `Y` intersect. Elements in `Y` with
     *     non-intersecting keys are appended, retaining their partial order.
     * 
     */
    private String rule;

    private ValidationRule() {}
    /**
     * @return fieldPath represents the field path returned when the validation fails. It must be a relative JSON path (i.e. with array notation) scoped to the location of this x-kubernetes-validations extension in the schema and refer to an existing field. e.g. when validation checks if a specific attribute `foo` under a map `testMap`, the fieldPath could be set to `.testMap.foo` If the validation checks two lists must have unique attributes, the fieldPath could be set to either of the list: e.g. `.testList` It does not support list numeric index. It supports child operation to refer to an existing field currently. Refer to [JSONPath support in Kubernetes](https://kubernetes.io/docs/reference/kubectl/jsonpath/) for more info. Numeric index of array is not supported. For field name which contains special characters, use `[&#39;specialName&#39;]` to refer the field name. e.g. for attribute `foo.34$` appears in a list `testList`, the fieldPath could be set to `.testList[&#39;foo.34$&#39;]`
     * 
     */
    public Optional<String> fieldPath() {
        return Optional.ofNullable(this.fieldPath);
    }
    /**
     * @return Message represents the message displayed when validation fails. The message is required if the Rule contains line breaks. The message must not contain line breaks. If unset, the message is &#34;failed rule: {Rule}&#34;. e.g. &#34;must be a URL with the host matching spec.host&#34;
     * 
     */
    public Optional<String> message() {
        return Optional.ofNullable(this.message);
    }
    /**
     * @return MessageExpression declares a CEL expression that evaluates to the validation failure message that is returned when this rule fails. Since messageExpression is used as a failure message, it must evaluate to a string. If both message and messageExpression are present on a rule, then messageExpression will be used if validation fails. If messageExpression results in a runtime error, the runtime error is logged, and the validation failure message is produced as if the messageExpression field were unset. If messageExpression evaluates to an empty string, a string with only spaces, or a string that contains line breaks, then the validation failure message will also be produced as if the messageExpression field were unset, and the fact that messageExpression produced an empty string/string with only spaces/string with line breaks will be logged. messageExpression has access to all the same variables as the rule; the only difference is the return type. Example: &#34;x must be less than max (&#34;+string(self.max)+&#34;)&#34;
     * 
     */
    public Optional<String> messageExpression() {
        return Optional.ofNullable(this.messageExpression);
    }
    /**
     * @return reason provides a machine-readable validation failure reason that is returned to the caller when a request fails this validation rule. The HTTP status code returned to the caller will match the reason of the reason of the first failed validation rule. The currently supported reasons are: &#34;FieldValueInvalid&#34;, &#34;FieldValueForbidden&#34;, &#34;FieldValueRequired&#34;, &#34;FieldValueDuplicate&#34;. If not set, default to use &#34;FieldValueInvalid&#34;. All future added reasons must be accepted by clients when reading this value and unknown reasons should be treated as FieldValueInvalid.
     * 
     */
    public Optional<String> reason() {
        return Optional.ofNullable(this.reason);
    }
    /**
     * @return Rule represents the expression which will be evaluated by CEL. ref: https://github.com/google/cel-spec The Rule is scoped to the location of the x-kubernetes-validations extension in the schema. The `self` variable in the CEL expression is bound to the scoped value. Example: - Rule scoped to the root of a resource with a status subresource: {&#34;rule&#34;: &#34;self.status.actual &lt;= self.spec.maxDesired&#34;}
     * 
     * If the Rule is scoped to an object with properties, the accessible properties of the object are field selectable via `self.field` and field presence can be checked via `has(self.field)`. Null valued fields are treated as absent fields in CEL expressions. If the Rule is scoped to an object with additionalProperties (i.e. a map) the value of the map are accessible via `self[mapKey]`, map containment can be checked via `mapKey in self` and all entries of the map are accessible via CEL macros and functions such as `self.all(...)`. If the Rule is scoped to an array, the elements of the array are accessible via `self[i]` and also by macros and functions. If the Rule is scoped to a scalar, `self` is bound to the scalar value. Examples: - Rule scoped to a map of objects: {&#34;rule&#34;: &#34;self.components[&#39;Widget&#39;].priority &lt; 10&#34;} - Rule scoped to a list of integers: {&#34;rule&#34;: &#34;self.values.all(value, value &gt;= 0 &amp;&amp; value &lt; 100)&#34;} - Rule scoped to a string value: {&#34;rule&#34;: &#34;self.startsWith(&#39;kube&#39;)&#34;}
     * 
     * The `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from the root of the object and from any x-kubernetes-embedded-resource annotated objects. No other metadata properties are accessible.
     * 
     * Unknown data preserved in custom resources via x-kubernetes-preserve-unknown-fields is not accessible in CEL expressions. This includes: - Unknown field values that are preserved by object schemas with x-kubernetes-preserve-unknown-fields. - Object properties where the property schema is of an &#34;unknown type&#34;. An &#34;unknown type&#34; is recursively defined as:
     *   - A schema with no type and x-kubernetes-preserve-unknown-fields set to true
     *   - An array where the items schema is of an &#34;unknown type&#34;
     *   - An object where the additionalProperties schema is of an &#34;unknown type&#34;
     * 
     * Only property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible. Accessible property names are escaped according to the following rules when accessed in the expression: - &#39;__&#39; escapes to &#39;__underscores__&#39; - &#39;.&#39; escapes to &#39;__dot__&#39; - &#39;-&#39; escapes to &#39;__dash__&#39; - &#39;/&#39; escapes to &#39;__slash__&#39; - Property names that exactly match a CEL RESERVED keyword escape to &#39;__{keyword}__&#39;. The keywords are:
     * 	  &#34;true&#34;, &#34;false&#34;, &#34;null&#34;, &#34;in&#34;, &#34;as&#34;, &#34;break&#34;, &#34;const&#34;, &#34;continue&#34;, &#34;else&#34;, &#34;for&#34;, &#34;function&#34;, &#34;if&#34;,
     * 	  &#34;import&#34;, &#34;let&#34;, &#34;loop&#34;, &#34;package&#34;, &#34;namespace&#34;, &#34;return&#34;.
     * Examples:
     *   - Rule accessing a property named &#34;namespace&#34;: {&#34;rule&#34;: &#34;self.__namespace__ &gt; 0&#34;}
     *   - Rule accessing a property named &#34;x-prop&#34;: {&#34;rule&#34;: &#34;self.x__dash__prop &gt; 0&#34;}
     *   - Rule accessing a property named &#34;redact__d&#34;: {&#34;rule&#34;: &#34;self.redact__underscores__d &gt; 0&#34;}
     * 
     * Equality on arrays with x-kubernetes-list-type of &#39;set&#39; or &#39;map&#39; ignores element order, i.e. [1, 2] == [2, 1]. Concatenation on arrays with x-kubernetes-list-type use the semantics of the list type:
     *   - &#39;set&#39;: `X + Y` performs a union where the array positions of all elements in `X` are preserved and
     *     non-intersecting elements in `Y` are appended, retaining their partial order.
     *   - &#39;map&#39;: `X + Y` performs a merge where the array positions of all keys in `X` are preserved but the values
     *     are overwritten by values in `Y` when the key sets of `X` and `Y` intersect. Elements in `Y` with
     *     non-intersecting keys are appended, retaining their partial order.
     * 
     */
    public String rule() {
        return this.rule;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static Builder builder(ValidationRule defaults) {
        return new Builder(defaults);
    }
    @CustomType.Builder
    public static final class Builder {
        private @Nullable String fieldPath;
        private @Nullable String message;
        private @Nullable String messageExpression;
        private @Nullable String reason;
        private String rule;
        public Builder() {}
        public Builder(ValidationRule defaults) {
    	      Objects.requireNonNull(defaults);
    	      this.fieldPath = defaults.fieldPath;
    	      this.message = defaults.message;
    	      this.messageExpression = defaults.messageExpression;
    	      this.reason = defaults.reason;
    	      this.rule = defaults.rule;
        }

        @CustomType.Setter
        public Builder fieldPath(@Nullable String fieldPath) {
            this.fieldPath = fieldPath;
            return this;
        }
        @CustomType.Setter
        public Builder message(@Nullable String message) {
            this.message = message;
            return this;
        }
        @CustomType.Setter
        public Builder messageExpression(@Nullable String messageExpression) {
            this.messageExpression = messageExpression;
            return this;
        }
        @CustomType.Setter
        public Builder reason(@Nullable String reason) {
            this.reason = reason;
            return this;
        }
        @CustomType.Setter
        public Builder rule(String rule) {
            this.rule = Objects.requireNonNull(rule);
            return this;
        }
        public ValidationRule build() {
            final var o = new ValidationRule();
            o.fieldPath = fieldPath;
            o.message = message;
            o.messageExpression = messageExpression;
            o.reason = reason;
            o.rule = rule;
            return o;
        }
    }
}
