/*
Copyright The Kubernetes Authors.

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.
*/

// Code generated by applyconfiguration-gen. DO NOT EDIT.

package v1

import (
	apisv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// CommonRouteSpecApplyConfiguration represents a declarative configuration of the CommonRouteSpec type for use
// with apply.
//
// CommonRouteSpec defines the common attributes that all Routes MUST include
// within their spec.
type CommonRouteSpecApplyConfiguration struct {
	// ParentRefs references the resources (usually Gateways) that a Route wants
	// to be attached to. Note that the referenced parent resource needs to
	// allow this for the attachment to be complete. For Gateways, that means
	// the Gateway needs to allow attachment from Routes of this kind and
	// namespace. For Services, that means the Service must either be in the same
	// namespace for a "producer" route, or the mesh implementation must support
	// and allow "consumer" routes for the referenced Service. ReferenceGrant is
	// not applicable for governing ParentRefs to Services - it is not possible to
	// create a "producer" route for a Service in a different namespace from the
	// Route.
	//
	// There are two kinds of parent resources with "Core" support:
	//
	// * Gateway (Gateway conformance profile)
	// * Service (Mesh conformance profile, ClusterIP Services only)
	//
	// This API may be extended in the future to support additional kinds of parent
	// resources.
	//
	// ParentRefs must be _distinct_. This means either that:
	//
	// * They select different objects.  If this is the case, then parentRef
	// entries are distinct. In terms of fields, this means that the
	// multi-part key defined by `group`, `kind`, `namespace`, and `name` must
	// be unique across all parentRef entries in the Route.
	// * They do not select different objects, but for each optional field used,
	// each ParentRef that selects the same object must set the same set of
	// optional fields to different values. If one ParentRef sets a
	// combination of optional fields, all must set the same combination.
	//
	// Some examples:
	//
	// * If one ParentRef sets `sectionName`, all ParentRefs referencing the
	// same object must also set `sectionName`.
	// * If one ParentRef sets `port`, all ParentRefs referencing the same
	// object must also set `port`.
	// * If one ParentRef sets `sectionName` and `port`, all ParentRefs
	// referencing the same object must also set `sectionName` and `port`.
	//
	// It is possible to separately reference multiple distinct objects that may
	// be collapsed by an implementation. For example, some implementations may
	// choose to merge compatible Gateway Listeners together. If that is the
	// case, the list of routes attached to those resources should also be
	// merged.
	//
	// Note that for ParentRefs that cross namespace boundaries, there are specific
	// rules. Cross-namespace references are only valid if they are explicitly
	// allowed by something in the namespace they are referring to. For example,
	// Gateway has the AllowedRoutes field, and ReferenceGrant provides a
	// generic way to enable other kinds of cross-namespace reference.
	//
	// <gateway:experimental:description>
	// ParentRefs from a Route to a Service in the same namespace are "producer"
	// routes, which apply default routing rules to inbound connections from
	// any namespace to the Service.
	//
	// ParentRefs from a Route to a Service in a different namespace are
	// "consumer" routes, and these routing rules are only applied to outbound
	// connections originating from the same namespace as the Route, for which
	// the intended destination of the connections are a Service targeted as a
	// ParentRef of the Route.
	// </gateway:experimental:description>
	//
	// <gateway:util:excludeFromCRD>
	// Ensures that when the same parent is referenced more than once, each reference
	// carries a distinct, non-empty sectionName. The first rule enforces consistency
	// (all refs specify sectionName or none do), the second enforces uniqueness.
	// </gateway:util:excludeFromCRD>
	// <gateway:standard:validation:XValidation:message="sectionName must be specified when parentRefs includes 2 or more references to the same parent",rule="self.all(p1, self.all(p2, p1.group == p2.group && p1.kind == p2.kind && p1.name == p2.name && (((!has(p1.__namespace__) || p1.__namespace__ == ”) && (!has(p2.__namespace__) || p2.__namespace__ == ”)) || (has(p1.__namespace__) && has(p2.__namespace__) && p1.__namespace__ == p2.__namespace__ )) ? ((!has(p1.sectionName) || p1.sectionName == ”) == (!has(p2.sectionName) || p2.sectionName == ”)) : true))">
	// <gateway:standard:validation:XValidation:message="sectionName must be unique when parentRefs includes 2 or more references to the same parent",rule="self.all(p1, self.exists_one(p2, p1.group == p2.group && p1.kind == p2.kind && p1.name == p2.name && (((!has(p1.__namespace__) || p1.__namespace__ == ”) && (!has(p2.__namespace__) || p2.__namespace__ == ”)) || (has(p1.__namespace__) && has(p2.__namespace__) && p1.__namespace__ == p2.__namespace__ )) && (((!has(p1.sectionName) || p1.sectionName == ”) && (!has(p2.sectionName) || p2.sectionName == ”)) || (has(p1.sectionName) && has(p2.sectionName) && p1.sectionName == p2.sectionName))))">
	// <gateway:util:excludeFromCRD>
	// Experimental variants of the above rules that additionally require the combination
	// of sectionName and port to be consistently specified and unique across refs.
	// </gateway:util:excludeFromCRD>
	// <gateway:experimental:validation:XValidation:message="sectionName or port must be specified when parentRefs includes 2 or more references to the same parent",rule="self.all(p1, self.all(p2, p1.group == p2.group && p1.kind == p2.kind && p1.name == p2.name && (((!has(p1.__namespace__) || p1.__namespace__ == ”) && (!has(p2.__namespace__) || p2.__namespace__ == ”)) || (has(p1.__namespace__) && has(p2.__namespace__) && p1.__namespace__ == p2.__namespace__)) ? ((!has(p1.sectionName) || p1.sectionName == ”) == (!has(p2.sectionName) || p2.sectionName == ”) && (!has(p1.port) || p1.port == 0) == (!has(p2.port) || p2.port == 0)): true))">
	// <gateway:experimental:validation:XValidation:message="sectionName or port must be unique when parentRefs includes 2 or more references to the same parent",rule="self.all(p1, self.exists_one(p2, p1.group == p2.group && p1.kind == p2.kind && p1.name == p2.name && (((!has(p1.__namespace__) || p1.__namespace__ == ”) && (!has(p2.__namespace__) || p2.__namespace__ == ”)) || (has(p1.__namespace__) && has(p2.__namespace__) && p1.__namespace__ == p2.__namespace__ )) && (((!has(p1.sectionName) || p1.sectionName == ”) && (!has(p2.sectionName) || p2.sectionName == ”)) || ( has(p1.sectionName) && has(p2.sectionName) && p1.sectionName == p2.sectionName)) && (((!has(p1.port) || p1.port == 0) && (!has(p2.port) || p2.port == 0)) || (has(p1.port) && has(p2.port) && p1.port == p2.port))))">
	ParentRefs []ParentReferenceApplyConfiguration `json:"parentRefs,omitempty"`
	// UseDefaultGateways indicates the default Gateway scope to use for this
	// Route. If unset (the default) or set to None, the Route will not be
	// attached to any default Gateway; if set, it will be attached to any
	// default Gateway supporting the named scope, subject to the usual rules
	// about which Routes a Gateway is allowed to claim.
	//
	// Think carefully before using this functionality! The set of default
	// Gateways supporting the requested scope can change over time without
	// any notice to the Route author, and in many situations it will not be
	// appropriate to request a default Gateway for a given Route -- for
	// example, a Route with specific security requirements should almost
	// certainly not use a default Gateway.
	//
	// <gateway:experimental>
	UseDefaultGateways *apisv1.GatewayDefaultScope `json:"useDefaultGateways,omitempty"`
}

// CommonRouteSpecApplyConfiguration constructs a declarative configuration of the CommonRouteSpec type for use with
// apply.
func CommonRouteSpec() *CommonRouteSpecApplyConfiguration {
	return &CommonRouteSpecApplyConfiguration{}
}

// WithParentRefs adds the given value to the ParentRefs field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the ParentRefs field.
func (b *CommonRouteSpecApplyConfiguration) WithParentRefs(values ...*ParentReferenceApplyConfiguration) *CommonRouteSpecApplyConfiguration {
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithParentRefs")
		}
		b.ParentRefs = append(b.ParentRefs, *values[i])
	}
	return b
}

// WithUseDefaultGateways sets the UseDefaultGateways field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the UseDefaultGateways field is set to the value of the last call.
func (b *CommonRouteSpecApplyConfiguration) WithUseDefaultGateways(value apisv1.GatewayDefaultScope) *CommonRouteSpecApplyConfiguration {
	b.UseDefaultGateways = &value
	return b
}
