// Code generated by azure-service-operator-codegen. DO NOT EDIT.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package v1api20220701

import (
	"fmt"
	v20220701s "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701/storage"
	"github.com/Azure/azure-service-operator/v2/internal/reflecthelpers"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions"
	"github.com/pkg/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"sigs.k8s.io/controller-runtime/pkg/conversion"
	"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="Severity",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].severity"
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].message"
// Generator information:
// - Generated from: /dnsresolver/resource-manager/Microsoft.Network/stable/2022-07-01/dnsresolver.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dnsForwardingRulesets/{dnsForwardingRulesetName}
type DnsForwardingRuleset struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              DnsForwardingRuleset_Spec   `json:"spec,omitempty"`
	Status            DnsForwardingRuleset_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &DnsForwardingRuleset{}

// GetConditions returns the conditions of the resource
func (ruleset *DnsForwardingRuleset) GetConditions() conditions.Conditions {
	return ruleset.Status.Conditions
}

// SetConditions sets the conditions on the resource status
func (ruleset *DnsForwardingRuleset) SetConditions(conditions conditions.Conditions) {
	ruleset.Status.Conditions = conditions
}

var _ conversion.Convertible = &DnsForwardingRuleset{}

// ConvertFrom populates our DnsForwardingRuleset from the provided hub DnsForwardingRuleset
func (ruleset *DnsForwardingRuleset) ConvertFrom(hub conversion.Hub) error {
	source, ok := hub.(*v20220701s.DnsForwardingRuleset)
	if !ok {
		return fmt.Errorf("expected network/v1api20220701/storage/DnsForwardingRuleset but received %T instead", hub)
	}

	return ruleset.AssignProperties_From_DnsForwardingRuleset(source)
}

// ConvertTo populates the provided hub DnsForwardingRuleset from our DnsForwardingRuleset
func (ruleset *DnsForwardingRuleset) ConvertTo(hub conversion.Hub) error {
	destination, ok := hub.(*v20220701s.DnsForwardingRuleset)
	if !ok {
		return fmt.Errorf("expected network/v1api20220701/storage/DnsForwardingRuleset but received %T instead", hub)
	}

	return ruleset.AssignProperties_To_DnsForwardingRuleset(destination)
}

// +kubebuilder:webhook:path=/mutate-network-azure-com-v1api20220701-dnsforwardingruleset,mutating=true,sideEffects=None,matchPolicy=Exact,failurePolicy=fail,groups=network.azure.com,resources=dnsforwardingrulesets,verbs=create;update,versions=v1api20220701,name=default.v1api20220701.dnsforwardingrulesets.network.azure.com,admissionReviewVersions=v1

var _ admission.Defaulter = &DnsForwardingRuleset{}

// Default applies defaults to the DnsForwardingRuleset resource
func (ruleset *DnsForwardingRuleset) Default() {
	ruleset.defaultImpl()
	var temp any = ruleset
	if runtimeDefaulter, ok := temp.(genruntime.Defaulter); ok {
		runtimeDefaulter.CustomDefault()
	}
}

// defaultAzureName defaults the Azure name of the resource to the Kubernetes name
func (ruleset *DnsForwardingRuleset) defaultAzureName() {
	if ruleset.Spec.AzureName == "" {
		ruleset.Spec.AzureName = ruleset.Name
	}
}

// defaultImpl applies the code generated defaults to the DnsForwardingRuleset resource
func (ruleset *DnsForwardingRuleset) defaultImpl() { ruleset.defaultAzureName() }

var _ genruntime.ImportableResource = &DnsForwardingRuleset{}

// InitializeSpec initializes the spec for this resource from the given status
func (ruleset *DnsForwardingRuleset) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*DnsForwardingRuleset_STATUS); ok {
		return ruleset.Spec.Initialize_From_DnsForwardingRuleset_STATUS(s)
	}

	return fmt.Errorf("expected Status of type DnsForwardingRuleset_STATUS but received %T instead", status)
}

var _ genruntime.KubernetesResource = &DnsForwardingRuleset{}

// AzureName returns the Azure name of the resource
func (ruleset *DnsForwardingRuleset) AzureName() string {
	return ruleset.Spec.AzureName
}

// GetAPIVersion returns the ARM API version of the resource. This is always "2022-07-01"
func (ruleset DnsForwardingRuleset) GetAPIVersion() string {
	return string(APIVersion_Value)
}

// GetResourceScope returns the scope of the resource
func (ruleset *DnsForwardingRuleset) GetResourceScope() genruntime.ResourceScope {
	return genruntime.ResourceScopeResourceGroup
}

// GetSpec returns the specification of this resource
func (ruleset *DnsForwardingRuleset) GetSpec() genruntime.ConvertibleSpec {
	return &ruleset.Spec
}

// GetStatus returns the status of this resource
func (ruleset *DnsForwardingRuleset) GetStatus() genruntime.ConvertibleStatus {
	return &ruleset.Status
}

// GetSupportedOperations returns the operations supported by the resource
func (ruleset *DnsForwardingRuleset) GetSupportedOperations() []genruntime.ResourceOperation {
	return []genruntime.ResourceOperation{
		genruntime.ResourceOperationDelete,
		genruntime.ResourceOperationGet,
		genruntime.ResourceOperationPut,
	}
}

// GetType returns the ARM Type of the resource. This is always "Microsoft.Network/dnsForwardingRulesets"
func (ruleset *DnsForwardingRuleset) GetType() string {
	return "Microsoft.Network/dnsForwardingRulesets"
}

// NewEmptyStatus returns a new empty (blank) status
func (ruleset *DnsForwardingRuleset) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &DnsForwardingRuleset_STATUS{}
}

// Owner returns the ResourceReference of the owner
func (ruleset *DnsForwardingRuleset) Owner() *genruntime.ResourceReference {
	group, kind := genruntime.LookupOwnerGroupKind(ruleset.Spec)
	return ruleset.Spec.Owner.AsResourceReference(group, kind)
}

// SetStatus sets the status of this resource
func (ruleset *DnsForwardingRuleset) SetStatus(status genruntime.ConvertibleStatus) error {
	// If we have exactly the right type of status, assign it
	if st, ok := status.(*DnsForwardingRuleset_STATUS); ok {
		ruleset.Status = *st
		return nil
	}

	// Convert status to required version
	var st DnsForwardingRuleset_STATUS
	err := status.ConvertStatusTo(&st)
	if err != nil {
		return errors.Wrap(err, "failed to convert status")
	}

	ruleset.Status = st
	return nil
}

// +kubebuilder:webhook:path=/validate-network-azure-com-v1api20220701-dnsforwardingruleset,mutating=false,sideEffects=None,matchPolicy=Exact,failurePolicy=fail,groups=network.azure.com,resources=dnsforwardingrulesets,verbs=create;update,versions=v1api20220701,name=validate.v1api20220701.dnsforwardingrulesets.network.azure.com,admissionReviewVersions=v1

var _ admission.Validator = &DnsForwardingRuleset{}

// ValidateCreate validates the creation of the resource
func (ruleset *DnsForwardingRuleset) ValidateCreate() (admission.Warnings, error) {
	validations := ruleset.createValidations()
	var temp any = ruleset
	if runtimeValidator, ok := temp.(genruntime.Validator); ok {
		validations = append(validations, runtimeValidator.CreateValidations()...)
	}
	return genruntime.ValidateCreate(validations)
}

// ValidateDelete validates the deletion of the resource
func (ruleset *DnsForwardingRuleset) ValidateDelete() (admission.Warnings, error) {
	validations := ruleset.deleteValidations()
	var temp any = ruleset
	if runtimeValidator, ok := temp.(genruntime.Validator); ok {
		validations = append(validations, runtimeValidator.DeleteValidations()...)
	}
	return genruntime.ValidateDelete(validations)
}

// ValidateUpdate validates an update of the resource
func (ruleset *DnsForwardingRuleset) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
	validations := ruleset.updateValidations()
	var temp any = ruleset
	if runtimeValidator, ok := temp.(genruntime.Validator); ok {
		validations = append(validations, runtimeValidator.UpdateValidations()...)
	}
	return genruntime.ValidateUpdate(old, validations)
}

// createValidations validates the creation of the resource
func (ruleset *DnsForwardingRuleset) createValidations() []func() (admission.Warnings, error) {
	return []func() (admission.Warnings, error){ruleset.validateResourceReferences, ruleset.validateOwnerReference}
}

// deleteValidations validates the deletion of the resource
func (ruleset *DnsForwardingRuleset) deleteValidations() []func() (admission.Warnings, error) {
	return nil
}

// updateValidations validates the update of the resource
func (ruleset *DnsForwardingRuleset) updateValidations() []func(old runtime.Object) (admission.Warnings, error) {
	return []func(old runtime.Object) (admission.Warnings, error){
		func(old runtime.Object) (admission.Warnings, error) {
			return ruleset.validateResourceReferences()
		},
		ruleset.validateWriteOnceProperties,
		func(old runtime.Object) (admission.Warnings, error) {
			return ruleset.validateOwnerReference()
		},
	}
}

// validateOwnerReference validates the owner field
func (ruleset *DnsForwardingRuleset) validateOwnerReference() (admission.Warnings, error) {
	return genruntime.ValidateOwner(ruleset)
}

// validateResourceReferences validates all resource references
func (ruleset *DnsForwardingRuleset) validateResourceReferences() (admission.Warnings, error) {
	refs, err := reflecthelpers.FindResourceReferences(&ruleset.Spec)
	if err != nil {
		return nil, err
	}
	return genruntime.ValidateResourceReferences(refs)
}

// validateWriteOnceProperties validates all WriteOnce properties
func (ruleset *DnsForwardingRuleset) validateWriteOnceProperties(old runtime.Object) (admission.Warnings, error) {
	oldObj, ok := old.(*DnsForwardingRuleset)
	if !ok {
		return nil, nil
	}

	return genruntime.ValidateWriteOnceProperties(oldObj, ruleset)
}

// AssignProperties_From_DnsForwardingRuleset populates our DnsForwardingRuleset from the provided source DnsForwardingRuleset
func (ruleset *DnsForwardingRuleset) AssignProperties_From_DnsForwardingRuleset(source *v20220701s.DnsForwardingRuleset) error {

	// ObjectMeta
	ruleset.ObjectMeta = *source.ObjectMeta.DeepCopy()

	// Spec
	var spec DnsForwardingRuleset_Spec
	err := spec.AssignProperties_From_DnsForwardingRuleset_Spec(&source.Spec)
	if err != nil {
		return errors.Wrap(err, "calling AssignProperties_From_DnsForwardingRuleset_Spec() to populate field Spec")
	}
	ruleset.Spec = spec

	// Status
	var status DnsForwardingRuleset_STATUS
	err = status.AssignProperties_From_DnsForwardingRuleset_STATUS(&source.Status)
	if err != nil {
		return errors.Wrap(err, "calling AssignProperties_From_DnsForwardingRuleset_STATUS() to populate field Status")
	}
	ruleset.Status = status

	// No error
	return nil
}

// AssignProperties_To_DnsForwardingRuleset populates the provided destination DnsForwardingRuleset from our DnsForwardingRuleset
func (ruleset *DnsForwardingRuleset) AssignProperties_To_DnsForwardingRuleset(destination *v20220701s.DnsForwardingRuleset) error {

	// ObjectMeta
	destination.ObjectMeta = *ruleset.ObjectMeta.DeepCopy()

	// Spec
	var spec v20220701s.DnsForwardingRuleset_Spec
	err := ruleset.Spec.AssignProperties_To_DnsForwardingRuleset_Spec(&spec)
	if err != nil {
		return errors.Wrap(err, "calling AssignProperties_To_DnsForwardingRuleset_Spec() to populate field Spec")
	}
	destination.Spec = spec

	// Status
	var status v20220701s.DnsForwardingRuleset_STATUS
	err = ruleset.Status.AssignProperties_To_DnsForwardingRuleset_STATUS(&status)
	if err != nil {
		return errors.Wrap(err, "calling AssignProperties_To_DnsForwardingRuleset_STATUS() to populate field Status")
	}
	destination.Status = status

	// No error
	return nil
}

// OriginalGVK returns a GroupValueKind for the original API version used to create the resource
func (ruleset *DnsForwardingRuleset) OriginalGVK() *schema.GroupVersionKind {
	return &schema.GroupVersionKind{
		Group:   GroupVersion.Group,
		Version: ruleset.Spec.OriginalVersion(),
		Kind:    "DnsForwardingRuleset",
	}
}

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /dnsresolver/resource-manager/Microsoft.Network/stable/2022-07-01/dnsresolver.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dnsForwardingRulesets/{dnsForwardingRulesetName}
type DnsForwardingRulesetList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []DnsForwardingRuleset `json:"items"`
}

type DnsForwardingRuleset_Spec struct {
	// AzureName: The name of the resource in Azure. This is often the same as the name of the resource in Kubernetes but it
	// doesn't have to be.
	AzureName string `json:"azureName,omitempty"`

	// +kubebuilder:validation:Required
	// DnsResolverOutboundEndpoints: The reference to the DNS resolver outbound endpoints that are used to route DNS queries
	// matching the forwarding rules in the ruleset to the target DNS servers.
	DnsResolverOutboundEndpoints []DnsresolverSubResource `json:"dnsResolverOutboundEndpoints,omitempty"`

	// +kubebuilder:validation:Required
	// Location: The geo-location where the resource lives
	Location *string `json:"location,omitempty"`

	// +kubebuilder:validation:Required
	// Owner: The owner of the resource. The owner controls where the resource goes when it is deployed. The owner also
	// controls the resources lifecycle. When the owner is deleted the resource will also be deleted. Owner is expected to be a
	// reference to a resources.azure.com/ResourceGroup resource
	Owner *genruntime.KnownResourceReference `group:"resources.azure.com" json:"owner,omitempty" kind:"ResourceGroup"`

	// Tags: Resource tags.
	Tags map[string]string `json:"tags,omitempty"`
}

var _ genruntime.ARMTransformer = &DnsForwardingRuleset_Spec{}

// ConvertToARM converts from a Kubernetes CRD object to an ARM object
func (ruleset *DnsForwardingRuleset_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (interface{}, error) {
	if ruleset == nil {
		return nil, nil
	}
	result := &DnsForwardingRuleset_Spec_ARM{}

	// Set property "Location":
	if ruleset.Location != nil {
		location := *ruleset.Location
		result.Location = &location
	}

	// Set property "Name":
	result.Name = resolved.Name

	// Set property "Properties":
	if ruleset.DnsResolverOutboundEndpoints != nil {
		result.Properties = &DnsForwardingRulesetProperties_ARM{}
	}
	for _, item := range ruleset.DnsResolverOutboundEndpoints {
		item_ARM, err := item.ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		result.Properties.DnsResolverOutboundEndpoints = append(result.Properties.DnsResolverOutboundEndpoints, *item_ARM.(*DnsresolverSubResource_ARM))
	}

	// Set property "Tags":
	if ruleset.Tags != nil {
		result.Tags = make(map[string]string, len(ruleset.Tags))
		for key, value := range ruleset.Tags {
			result.Tags[key] = value
		}
	}
	return result, nil
}

// NewEmptyARMValue returns an empty ARM value suitable for deserializing into
func (ruleset *DnsForwardingRuleset_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus {
	return &DnsForwardingRuleset_Spec_ARM{}
}

// PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object
func (ruleset *DnsForwardingRuleset_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error {
	typedInput, ok := armInput.(DnsForwardingRuleset_Spec_ARM)
	if !ok {
		return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected DnsForwardingRuleset_Spec_ARM, got %T", armInput)
	}

	// Set property "AzureName":
	ruleset.SetAzureName(genruntime.ExtractKubernetesResourceNameFromARMName(typedInput.Name))

	// Set property "DnsResolverOutboundEndpoints":
	// copying flattened property:
	if typedInput.Properties != nil {
		for _, item := range typedInput.Properties.DnsResolverOutboundEndpoints {
			var item1 DnsresolverSubResource
			err := item1.PopulateFromARM(owner, item)
			if err != nil {
				return err
			}
			ruleset.DnsResolverOutboundEndpoints = append(ruleset.DnsResolverOutboundEndpoints, item1)
		}
	}

	// Set property "Location":
	if typedInput.Location != nil {
		location := *typedInput.Location
		ruleset.Location = &location
	}

	// Set property "Owner":
	ruleset.Owner = &genruntime.KnownResourceReference{
		Name:  owner.Name,
		ARMID: owner.ARMID,
	}

	// Set property "Tags":
	if typedInput.Tags != nil {
		ruleset.Tags = make(map[string]string, len(typedInput.Tags))
		for key, value := range typedInput.Tags {
			ruleset.Tags[key] = value
		}
	}

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &DnsForwardingRuleset_Spec{}

// ConvertSpecFrom populates our DnsForwardingRuleset_Spec from the provided source
func (ruleset *DnsForwardingRuleset_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error {
	src, ok := source.(*v20220701s.DnsForwardingRuleset_Spec)
	if ok {
		// Populate our instance from source
		return ruleset.AssignProperties_From_DnsForwardingRuleset_Spec(src)
	}

	// Convert to an intermediate form
	src = &v20220701s.DnsForwardingRuleset_Spec{}
	err := src.ConvertSpecFrom(source)
	if err != nil {
		return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()")
	}

	// Update our instance from src
	err = ruleset.AssignProperties_From_DnsForwardingRuleset_Spec(src)
	if err != nil {
		return errors.Wrap(err, "final step of conversion in ConvertSpecFrom()")
	}

	return nil
}

// ConvertSpecTo populates the provided destination from our DnsForwardingRuleset_Spec
func (ruleset *DnsForwardingRuleset_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error {
	dst, ok := destination.(*v20220701s.DnsForwardingRuleset_Spec)
	if ok {
		// Populate destination from our instance
		return ruleset.AssignProperties_To_DnsForwardingRuleset_Spec(dst)
	}

	// Convert to an intermediate form
	dst = &v20220701s.DnsForwardingRuleset_Spec{}
	err := ruleset.AssignProperties_To_DnsForwardingRuleset_Spec(dst)
	if err != nil {
		return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()")
	}

	// Update dst from our instance
	err = dst.ConvertSpecTo(destination)
	if err != nil {
		return errors.Wrap(err, "final step of conversion in ConvertSpecTo()")
	}

	return nil
}

// AssignProperties_From_DnsForwardingRuleset_Spec populates our DnsForwardingRuleset_Spec from the provided source DnsForwardingRuleset_Spec
func (ruleset *DnsForwardingRuleset_Spec) AssignProperties_From_DnsForwardingRuleset_Spec(source *v20220701s.DnsForwardingRuleset_Spec) error {

	// AzureName
	ruleset.AzureName = source.AzureName

	// DnsResolverOutboundEndpoints
	if source.DnsResolverOutboundEndpoints != nil {
		dnsResolverOutboundEndpointList := make([]DnsresolverSubResource, len(source.DnsResolverOutboundEndpoints))
		for dnsResolverOutboundEndpointIndex, dnsResolverOutboundEndpointItem := range source.DnsResolverOutboundEndpoints {
			// Shadow the loop variable to avoid aliasing
			dnsResolverOutboundEndpointItem := dnsResolverOutboundEndpointItem
			var dnsResolverOutboundEndpoint DnsresolverSubResource
			err := dnsResolverOutboundEndpoint.AssignProperties_From_DnsresolverSubResource(&dnsResolverOutboundEndpointItem)
			if err != nil {
				return errors.Wrap(err, "calling AssignProperties_From_DnsresolverSubResource() to populate field DnsResolverOutboundEndpoints")
			}
			dnsResolverOutboundEndpointList[dnsResolverOutboundEndpointIndex] = dnsResolverOutboundEndpoint
		}
		ruleset.DnsResolverOutboundEndpoints = dnsResolverOutboundEndpointList
	} else {
		ruleset.DnsResolverOutboundEndpoints = nil
	}

	// Location
	ruleset.Location = genruntime.ClonePointerToString(source.Location)

	// Owner
	if source.Owner != nil {
		owner := source.Owner.Copy()
		ruleset.Owner = &owner
	} else {
		ruleset.Owner = nil
	}

	// Tags
	ruleset.Tags = genruntime.CloneMapOfStringToString(source.Tags)

	// No error
	return nil
}

// AssignProperties_To_DnsForwardingRuleset_Spec populates the provided destination DnsForwardingRuleset_Spec from our DnsForwardingRuleset_Spec
func (ruleset *DnsForwardingRuleset_Spec) AssignProperties_To_DnsForwardingRuleset_Spec(destination *v20220701s.DnsForwardingRuleset_Spec) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// AzureName
	destination.AzureName = ruleset.AzureName

	// DnsResolverOutboundEndpoints
	if ruleset.DnsResolverOutboundEndpoints != nil {
		dnsResolverOutboundEndpointList := make([]v20220701s.DnsresolverSubResource, len(ruleset.DnsResolverOutboundEndpoints))
		for dnsResolverOutboundEndpointIndex, dnsResolverOutboundEndpointItem := range ruleset.DnsResolverOutboundEndpoints {
			// Shadow the loop variable to avoid aliasing
			dnsResolverOutboundEndpointItem := dnsResolverOutboundEndpointItem
			var dnsResolverOutboundEndpoint v20220701s.DnsresolverSubResource
			err := dnsResolverOutboundEndpointItem.AssignProperties_To_DnsresolverSubResource(&dnsResolverOutboundEndpoint)
			if err != nil {
				return errors.Wrap(err, "calling AssignProperties_To_DnsresolverSubResource() to populate field DnsResolverOutboundEndpoints")
			}
			dnsResolverOutboundEndpointList[dnsResolverOutboundEndpointIndex] = dnsResolverOutboundEndpoint
		}
		destination.DnsResolverOutboundEndpoints = dnsResolverOutboundEndpointList
	} else {
		destination.DnsResolverOutboundEndpoints = nil
	}

	// Location
	destination.Location = genruntime.ClonePointerToString(ruleset.Location)

	// OriginalVersion
	destination.OriginalVersion = ruleset.OriginalVersion()

	// Owner
	if ruleset.Owner != nil {
		owner := ruleset.Owner.Copy()
		destination.Owner = &owner
	} else {
		destination.Owner = nil
	}

	// Tags
	destination.Tags = genruntime.CloneMapOfStringToString(ruleset.Tags)

	// Update the property bag
	if len(propertyBag) > 0 {
		destination.PropertyBag = propertyBag
	} else {
		destination.PropertyBag = nil
	}

	// No error
	return nil
}

// Initialize_From_DnsForwardingRuleset_STATUS populates our DnsForwardingRuleset_Spec from the provided source DnsForwardingRuleset_STATUS
func (ruleset *DnsForwardingRuleset_Spec) Initialize_From_DnsForwardingRuleset_STATUS(source *DnsForwardingRuleset_STATUS) error {

	// DnsResolverOutboundEndpoints
	if source.DnsResolverOutboundEndpoints != nil {
		dnsResolverOutboundEndpointList := make([]DnsresolverSubResource, len(source.DnsResolverOutboundEndpoints))
		for dnsResolverOutboundEndpointIndex, dnsResolverOutboundEndpointItem := range source.DnsResolverOutboundEndpoints {
			// Shadow the loop variable to avoid aliasing
			dnsResolverOutboundEndpointItem := dnsResolverOutboundEndpointItem
			var dnsResolverOutboundEndpoint DnsresolverSubResource
			err := dnsResolverOutboundEndpoint.Initialize_From_DnsresolverSubResource_STATUS(&dnsResolverOutboundEndpointItem)
			if err != nil {
				return errors.Wrap(err, "calling Initialize_From_DnsresolverSubResource_STATUS() to populate field DnsResolverOutboundEndpoints")
			}
			dnsResolverOutboundEndpointList[dnsResolverOutboundEndpointIndex] = dnsResolverOutboundEndpoint
		}
		ruleset.DnsResolverOutboundEndpoints = dnsResolverOutboundEndpointList
	} else {
		ruleset.DnsResolverOutboundEndpoints = nil
	}

	// Location
	ruleset.Location = genruntime.ClonePointerToString(source.Location)

	// Tags
	ruleset.Tags = genruntime.CloneMapOfStringToString(source.Tags)

	// No error
	return nil
}

// OriginalVersion returns the original API version used to create the resource.
func (ruleset *DnsForwardingRuleset_Spec) OriginalVersion() string {
	return GroupVersion.Version
}

// SetAzureName sets the Azure name of the resource
func (ruleset *DnsForwardingRuleset_Spec) SetAzureName(azureName string) {
	ruleset.AzureName = azureName
}

// Describes a DNS forwarding ruleset.
type DnsForwardingRuleset_STATUS struct {
	// Conditions: The observed state of the resource
	Conditions []conditions.Condition `json:"conditions,omitempty"`

	// DnsResolverOutboundEndpoints: The reference to the DNS resolver outbound endpoints that are used to route DNS queries
	// matching the forwarding rules in the ruleset to the target DNS servers.
	DnsResolverOutboundEndpoints []DnsresolverSubResource_STATUS `json:"dnsResolverOutboundEndpoints,omitempty"`

	// Etag: ETag of the DNS forwarding ruleset.
	Etag *string `json:"etag,omitempty"`

	// Id: Fully qualified resource ID for the resource. Ex -
	// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}
	Id *string `json:"id,omitempty"`

	// Location: The geo-location where the resource lives
	Location *string `json:"location,omitempty"`

	// Name: The name of the resource
	Name *string `json:"name,omitempty"`

	// ProvisioningState: The current provisioning state of the DNS forwarding ruleset. This is a read-only property and any
	// attempt to set this value will be ignored.
	ProvisioningState *DnsresolverProvisioningState_STATUS `json:"provisioningState,omitempty"`

	// ResourceGuid: The resourceGuid for the DNS forwarding ruleset.
	ResourceGuid *string `json:"resourceGuid,omitempty"`

	// SystemData: Metadata pertaining to creation and last modification of the resource.
	SystemData *SystemData_STATUS `json:"systemData,omitempty"`

	// Tags: Resource tags.
	Tags map[string]string `json:"tags,omitempty"`

	// Type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts"
	Type *string `json:"type,omitempty"`
}

var _ genruntime.ConvertibleStatus = &DnsForwardingRuleset_STATUS{}

// ConvertStatusFrom populates our DnsForwardingRuleset_STATUS from the provided source
func (ruleset *DnsForwardingRuleset_STATUS) ConvertStatusFrom(source genruntime.ConvertibleStatus) error {
	src, ok := source.(*v20220701s.DnsForwardingRuleset_STATUS)
	if ok {
		// Populate our instance from source
		return ruleset.AssignProperties_From_DnsForwardingRuleset_STATUS(src)
	}

	// Convert to an intermediate form
	src = &v20220701s.DnsForwardingRuleset_STATUS{}
	err := src.ConvertStatusFrom(source)
	if err != nil {
		return errors.Wrap(err, "initial step of conversion in ConvertStatusFrom()")
	}

	// Update our instance from src
	err = ruleset.AssignProperties_From_DnsForwardingRuleset_STATUS(src)
	if err != nil {
		return errors.Wrap(err, "final step of conversion in ConvertStatusFrom()")
	}

	return nil
}

// ConvertStatusTo populates the provided destination from our DnsForwardingRuleset_STATUS
func (ruleset *DnsForwardingRuleset_STATUS) ConvertStatusTo(destination genruntime.ConvertibleStatus) error {
	dst, ok := destination.(*v20220701s.DnsForwardingRuleset_STATUS)
	if ok {
		// Populate destination from our instance
		return ruleset.AssignProperties_To_DnsForwardingRuleset_STATUS(dst)
	}

	// Convert to an intermediate form
	dst = &v20220701s.DnsForwardingRuleset_STATUS{}
	err := ruleset.AssignProperties_To_DnsForwardingRuleset_STATUS(dst)
	if err != nil {
		return errors.Wrap(err, "initial step of conversion in ConvertStatusTo()")
	}

	// Update dst from our instance
	err = dst.ConvertStatusTo(destination)
	if err != nil {
		return errors.Wrap(err, "final step of conversion in ConvertStatusTo()")
	}

	return nil
}

var _ genruntime.FromARMConverter = &DnsForwardingRuleset_STATUS{}

// NewEmptyARMValue returns an empty ARM value suitable for deserializing into
func (ruleset *DnsForwardingRuleset_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus {
	return &DnsForwardingRuleset_STATUS_ARM{}
}

// PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object
func (ruleset *DnsForwardingRuleset_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error {
	typedInput, ok := armInput.(DnsForwardingRuleset_STATUS_ARM)
	if !ok {
		return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected DnsForwardingRuleset_STATUS_ARM, got %T", armInput)
	}

	// no assignment for property "Conditions"

	// Set property "DnsResolverOutboundEndpoints":
	// copying flattened property:
	if typedInput.Properties != nil {
		for _, item := range typedInput.Properties.DnsResolverOutboundEndpoints {
			var item1 DnsresolverSubResource_STATUS
			err := item1.PopulateFromARM(owner, item)
			if err != nil {
				return err
			}
			ruleset.DnsResolverOutboundEndpoints = append(ruleset.DnsResolverOutboundEndpoints, item1)
		}
	}

	// Set property "Etag":
	if typedInput.Etag != nil {
		etag := *typedInput.Etag
		ruleset.Etag = &etag
	}

	// Set property "Id":
	if typedInput.Id != nil {
		id := *typedInput.Id
		ruleset.Id = &id
	}

	// Set property "Location":
	if typedInput.Location != nil {
		location := *typedInput.Location
		ruleset.Location = &location
	}

	// Set property "Name":
	if typedInput.Name != nil {
		name := *typedInput.Name
		ruleset.Name = &name
	}

	// Set property "ProvisioningState":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ProvisioningState != nil {
			provisioningState := *typedInput.Properties.ProvisioningState
			ruleset.ProvisioningState = &provisioningState
		}
	}

	// Set property "ResourceGuid":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ResourceGuid != nil {
			resourceGuid := *typedInput.Properties.ResourceGuid
			ruleset.ResourceGuid = &resourceGuid
		}
	}

	// Set property "SystemData":
	if typedInput.SystemData != nil {
		var systemData1 SystemData_STATUS
		err := systemData1.PopulateFromARM(owner, *typedInput.SystemData)
		if err != nil {
			return err
		}
		systemData := systemData1
		ruleset.SystemData = &systemData
	}

	// Set property "Tags":
	if typedInput.Tags != nil {
		ruleset.Tags = make(map[string]string, len(typedInput.Tags))
		for key, value := range typedInput.Tags {
			ruleset.Tags[key] = value
		}
	}

	// Set property "Type":
	if typedInput.Type != nil {
		typeVar := *typedInput.Type
		ruleset.Type = &typeVar
	}

	// No error
	return nil
}

// AssignProperties_From_DnsForwardingRuleset_STATUS populates our DnsForwardingRuleset_STATUS from the provided source DnsForwardingRuleset_STATUS
func (ruleset *DnsForwardingRuleset_STATUS) AssignProperties_From_DnsForwardingRuleset_STATUS(source *v20220701s.DnsForwardingRuleset_STATUS) error {

	// Conditions
	ruleset.Conditions = genruntime.CloneSliceOfCondition(source.Conditions)

	// DnsResolverOutboundEndpoints
	if source.DnsResolverOutboundEndpoints != nil {
		dnsResolverOutboundEndpointList := make([]DnsresolverSubResource_STATUS, len(source.DnsResolverOutboundEndpoints))
		for dnsResolverOutboundEndpointIndex, dnsResolverOutboundEndpointItem := range source.DnsResolverOutboundEndpoints {
			// Shadow the loop variable to avoid aliasing
			dnsResolverOutboundEndpointItem := dnsResolverOutboundEndpointItem
			var dnsResolverOutboundEndpoint DnsresolverSubResource_STATUS
			err := dnsResolverOutboundEndpoint.AssignProperties_From_DnsresolverSubResource_STATUS(&dnsResolverOutboundEndpointItem)
			if err != nil {
				return errors.Wrap(err, "calling AssignProperties_From_DnsresolverSubResource_STATUS() to populate field DnsResolverOutboundEndpoints")
			}
			dnsResolverOutboundEndpointList[dnsResolverOutboundEndpointIndex] = dnsResolverOutboundEndpoint
		}
		ruleset.DnsResolverOutboundEndpoints = dnsResolverOutboundEndpointList
	} else {
		ruleset.DnsResolverOutboundEndpoints = nil
	}

	// Etag
	ruleset.Etag = genruntime.ClonePointerToString(source.Etag)

	// Id
	ruleset.Id = genruntime.ClonePointerToString(source.Id)

	// Location
	ruleset.Location = genruntime.ClonePointerToString(source.Location)

	// Name
	ruleset.Name = genruntime.ClonePointerToString(source.Name)

	// ProvisioningState
	if source.ProvisioningState != nil {
		provisioningState := DnsresolverProvisioningState_STATUS(*source.ProvisioningState)
		ruleset.ProvisioningState = &provisioningState
	} else {
		ruleset.ProvisioningState = nil
	}

	// ResourceGuid
	ruleset.ResourceGuid = genruntime.ClonePointerToString(source.ResourceGuid)

	// SystemData
	if source.SystemData != nil {
		var systemDatum SystemData_STATUS
		err := systemDatum.AssignProperties_From_SystemData_STATUS(source.SystemData)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_From_SystemData_STATUS() to populate field SystemData")
		}
		ruleset.SystemData = &systemDatum
	} else {
		ruleset.SystemData = nil
	}

	// Tags
	ruleset.Tags = genruntime.CloneMapOfStringToString(source.Tags)

	// Type
	ruleset.Type = genruntime.ClonePointerToString(source.Type)

	// No error
	return nil
}

// AssignProperties_To_DnsForwardingRuleset_STATUS populates the provided destination DnsForwardingRuleset_STATUS from our DnsForwardingRuleset_STATUS
func (ruleset *DnsForwardingRuleset_STATUS) AssignProperties_To_DnsForwardingRuleset_STATUS(destination *v20220701s.DnsForwardingRuleset_STATUS) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// Conditions
	destination.Conditions = genruntime.CloneSliceOfCondition(ruleset.Conditions)

	// DnsResolverOutboundEndpoints
	if ruleset.DnsResolverOutboundEndpoints != nil {
		dnsResolverOutboundEndpointList := make([]v20220701s.DnsresolverSubResource_STATUS, len(ruleset.DnsResolverOutboundEndpoints))
		for dnsResolverOutboundEndpointIndex, dnsResolverOutboundEndpointItem := range ruleset.DnsResolverOutboundEndpoints {
			// Shadow the loop variable to avoid aliasing
			dnsResolverOutboundEndpointItem := dnsResolverOutboundEndpointItem
			var dnsResolverOutboundEndpoint v20220701s.DnsresolverSubResource_STATUS
			err := dnsResolverOutboundEndpointItem.AssignProperties_To_DnsresolverSubResource_STATUS(&dnsResolverOutboundEndpoint)
			if err != nil {
				return errors.Wrap(err, "calling AssignProperties_To_DnsresolverSubResource_STATUS() to populate field DnsResolverOutboundEndpoints")
			}
			dnsResolverOutboundEndpointList[dnsResolverOutboundEndpointIndex] = dnsResolverOutboundEndpoint
		}
		destination.DnsResolverOutboundEndpoints = dnsResolverOutboundEndpointList
	} else {
		destination.DnsResolverOutboundEndpoints = nil
	}

	// Etag
	destination.Etag = genruntime.ClonePointerToString(ruleset.Etag)

	// Id
	destination.Id = genruntime.ClonePointerToString(ruleset.Id)

	// Location
	destination.Location = genruntime.ClonePointerToString(ruleset.Location)

	// Name
	destination.Name = genruntime.ClonePointerToString(ruleset.Name)

	// ProvisioningState
	if ruleset.ProvisioningState != nil {
		provisioningState := string(*ruleset.ProvisioningState)
		destination.ProvisioningState = &provisioningState
	} else {
		destination.ProvisioningState = nil
	}

	// ResourceGuid
	destination.ResourceGuid = genruntime.ClonePointerToString(ruleset.ResourceGuid)

	// SystemData
	if ruleset.SystemData != nil {
		var systemDatum v20220701s.SystemData_STATUS
		err := ruleset.SystemData.AssignProperties_To_SystemData_STATUS(&systemDatum)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_To_SystemData_STATUS() to populate field SystemData")
		}
		destination.SystemData = &systemDatum
	} else {
		destination.SystemData = nil
	}

	// Tags
	destination.Tags = genruntime.CloneMapOfStringToString(ruleset.Tags)

	// Type
	destination.Type = genruntime.ClonePointerToString(ruleset.Type)

	// Update the property bag
	if len(propertyBag) > 0 {
		destination.PropertyBag = propertyBag
	} else {
		destination.PropertyBag = nil
	}

	// No error
	return nil
}

// Reference to another ARM resource.
type DnsresolverSubResource struct {
	// +kubebuilder:validation:Required
	// Reference: Resource ID.
	Reference *genruntime.ResourceReference `armReference:"Id" json:"reference,omitempty"`
}

var _ genruntime.ARMTransformer = &DnsresolverSubResource{}

// ConvertToARM converts from a Kubernetes CRD object to an ARM object
func (resource *DnsresolverSubResource) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (interface{}, error) {
	if resource == nil {
		return nil, nil
	}
	result := &DnsresolverSubResource_ARM{}

	// Set property "Id":
	if resource.Reference != nil {
		referenceARMID, err := resolved.ResolvedReferences.Lookup(*resource.Reference)
		if err != nil {
			return nil, err
		}
		reference := referenceARMID
		result.Id = &reference
	}
	return result, nil
}

// NewEmptyARMValue returns an empty ARM value suitable for deserializing into
func (resource *DnsresolverSubResource) NewEmptyARMValue() genruntime.ARMResourceStatus {
	return &DnsresolverSubResource_ARM{}
}

// PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object
func (resource *DnsresolverSubResource) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error {
	_, ok := armInput.(DnsresolverSubResource_ARM)
	if !ok {
		return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected DnsresolverSubResource_ARM, got %T", armInput)
	}

	// no assignment for property "Reference"

	// No error
	return nil
}

// AssignProperties_From_DnsresolverSubResource populates our DnsresolverSubResource from the provided source DnsresolverSubResource
func (resource *DnsresolverSubResource) AssignProperties_From_DnsresolverSubResource(source *v20220701s.DnsresolverSubResource) error {

	// Reference
	if source.Reference != nil {
		reference := source.Reference.Copy()
		resource.Reference = &reference
	} else {
		resource.Reference = nil
	}

	// No error
	return nil
}

// AssignProperties_To_DnsresolverSubResource populates the provided destination DnsresolverSubResource from our DnsresolverSubResource
func (resource *DnsresolverSubResource) AssignProperties_To_DnsresolverSubResource(destination *v20220701s.DnsresolverSubResource) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// Reference
	if resource.Reference != nil {
		reference := resource.Reference.Copy()
		destination.Reference = &reference
	} else {
		destination.Reference = nil
	}

	// Update the property bag
	if len(propertyBag) > 0 {
		destination.PropertyBag = propertyBag
	} else {
		destination.PropertyBag = nil
	}

	// No error
	return nil
}

// Initialize_From_DnsresolverSubResource_STATUS populates our DnsresolverSubResource from the provided source DnsresolverSubResource_STATUS
func (resource *DnsresolverSubResource) Initialize_From_DnsresolverSubResource_STATUS(source *DnsresolverSubResource_STATUS) error {

	// Reference
	if source.Id != nil {
		reference := genruntime.CreateResourceReferenceFromARMID(*source.Id)
		resource.Reference = &reference
	} else {
		resource.Reference = nil
	}

	// No error
	return nil
}

// Reference to another ARM resource.
type DnsresolverSubResource_STATUS struct {
	// Id: Resource ID.
	Id *string `json:"id,omitempty"`
}

var _ genruntime.FromARMConverter = &DnsresolverSubResource_STATUS{}

// NewEmptyARMValue returns an empty ARM value suitable for deserializing into
func (resource *DnsresolverSubResource_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus {
	return &DnsresolverSubResource_STATUS_ARM{}
}

// PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object
func (resource *DnsresolverSubResource_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error {
	typedInput, ok := armInput.(DnsresolverSubResource_STATUS_ARM)
	if !ok {
		return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected DnsresolverSubResource_STATUS_ARM, got %T", armInput)
	}

	// Set property "Id":
	if typedInput.Id != nil {
		id := *typedInput.Id
		resource.Id = &id
	}

	// No error
	return nil
}

// AssignProperties_From_DnsresolverSubResource_STATUS populates our DnsresolverSubResource_STATUS from the provided source DnsresolverSubResource_STATUS
func (resource *DnsresolverSubResource_STATUS) AssignProperties_From_DnsresolverSubResource_STATUS(source *v20220701s.DnsresolverSubResource_STATUS) error {

	// Id
	resource.Id = genruntime.ClonePointerToString(source.Id)

	// No error
	return nil
}

// AssignProperties_To_DnsresolverSubResource_STATUS populates the provided destination DnsresolverSubResource_STATUS from our DnsresolverSubResource_STATUS
func (resource *DnsresolverSubResource_STATUS) AssignProperties_To_DnsresolverSubResource_STATUS(destination *v20220701s.DnsresolverSubResource_STATUS) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// Id
	destination.Id = genruntime.ClonePointerToString(resource.Id)

	// Update the property bag
	if len(propertyBag) > 0 {
		destination.PropertyBag = propertyBag
	} else {
		destination.PropertyBag = nil
	}

	// No error
	return nil
}

func init() {
	SchemeBuilder.Register(&DnsForwardingRuleset{}, &DnsForwardingRulesetList{})
}
