/*
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"
)

// GRPCRouteSpecApplyConfiguration represents a declarative configuration of the GRPCRouteSpec type for use
// with apply.
//
// GRPCRouteSpec defines the desired state of GRPCRoute
type GRPCRouteSpecApplyConfiguration struct {
	CommonRouteSpecApplyConfiguration `json:",inline"`
	// Hostnames defines a set of hostnames to match against the GRPC
	// Host header to select a GRPCRoute to process the request. This matches
	// the RFC 1123 definition of a hostname with 2 notable exceptions:
	//
	// 1. IPs are not allowed.
	// 2. A hostname may be prefixed with a wildcard label (`*.`). The wildcard
	// label MUST appear by itself as the first label.
	//
	// If a hostname is specified by both the Listener and GRPCRoute, there
	// MUST be at least one intersecting hostname for the GRPCRoute to be
	// attached to the Listener. For example:
	//
	// * A Listener with `test.example.com` as the hostname matches GRPCRoutes
	// that have either not specified any hostnames, or have specified at
	// least one of `test.example.com` or `*.example.com`.
	// * A Listener with `*.example.com` as the hostname matches GRPCRoutes
	// that have either not specified any hostnames or have specified at least
	// one hostname that matches the Listener hostname. For example,
	// `test.example.com` and `*.example.com` would both match. On the other
	// hand, `example.com` and `test.example.net` would not match.
	//
	// Hostnames that are prefixed with a wildcard label (`*.`) are interpreted
	// as a suffix match. That means that a match for `*.example.com` would match
	// both `test.example.com`, and `foo.test.example.com`, but not `example.com`.
	//
	// If both the Listener and GRPCRoute have specified hostnames, any
	// GRPCRoute hostnames that do not match the Listener hostname MUST be
	// ignored. For example, if a Listener specified `*.example.com`, and the
	// GRPCRoute specified `test.example.com` and `test.example.net`,
	// `test.example.net` MUST NOT be considered for a match.
	//
	// If both the Listener and GRPCRoute have specified hostnames, and none
	// match with the criteria above, then the GRPCRoute MUST NOT be accepted by
	// the implementation. The implementation MUST raise an 'Accepted' Condition
	// with a status of `False` in the corresponding RouteParentStatus.
	//
	// If a Route (A) of type HTTPRoute or GRPCRoute is attached to a
	// Listener and that listener already has another Route (B) of the other
	// type attached and the intersection of the hostnames of A and B is
	// non-empty, then the implementation MUST accept exactly one of these two
	// routes, determined by the following criteria, in order:
	//
	// * The oldest Route based on creation timestamp.
	// * The Route appearing first in alphabetical order by
	// "{namespace}/{name}".
	//
	// The rejected Route MUST raise an 'Accepted' condition with a status of
	// 'False' in the corresponding RouteParentStatus.
	//
	// Support: Core
	Hostnames []apisv1.Hostname `json:"hostnames,omitempty"`
	// Rules are a list of GRPC matchers, filters and actions.
	//
	// <gateway:experimental:validation:XValidation:message="Rule name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))">
	Rules []GRPCRouteRuleApplyConfiguration `json:"rules,omitempty"`
}

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

// 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 *GRPCRouteSpecApplyConfiguration) WithParentRefs(values ...*ParentReferenceApplyConfiguration) *GRPCRouteSpecApplyConfiguration {
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithParentRefs")
		}
		b.CommonRouteSpecApplyConfiguration.ParentRefs = append(b.CommonRouteSpecApplyConfiguration.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 *GRPCRouteSpecApplyConfiguration) WithUseDefaultGateways(value apisv1.GatewayDefaultScope) *GRPCRouteSpecApplyConfiguration {
	b.CommonRouteSpecApplyConfiguration.UseDefaultGateways = &value
	return b
}

// WithHostnames adds the given value to the Hostnames 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 Hostnames field.
func (b *GRPCRouteSpecApplyConfiguration) WithHostnames(values ...apisv1.Hostname) *GRPCRouteSpecApplyConfiguration {
	for i := range values {
		b.Hostnames = append(b.Hostnames, values[i])
	}
	return b
}

// WithRules adds the given value to the Rules 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 Rules field.
func (b *GRPCRouteSpecApplyConfiguration) WithRules(values ...*GRPCRouteRuleApplyConfiguration) *GRPCRouteSpecApplyConfiguration {
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithRules")
		}
		b.Rules = append(b.Rules, *values[i])
	}
	return b
}
