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

import (
	"fmt"
	v20201101s "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101/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: /network/resource-manager/Microsoft.Network/stable/2020-11-01/virtualNetwork.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/virtualNetworkPeerings/{virtualNetworkPeeringName}
type VirtualNetworksVirtualNetworkPeering struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              VirtualNetworks_VirtualNetworkPeering_Spec   `json:"spec,omitempty"`
	Status            VirtualNetworks_VirtualNetworkPeering_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &VirtualNetworksVirtualNetworkPeering{}

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

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

var _ conversion.Convertible = &VirtualNetworksVirtualNetworkPeering{}

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

	return peering.AssignProperties_From_VirtualNetworksVirtualNetworkPeering(source)
}

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

	return peering.AssignProperties_To_VirtualNetworksVirtualNetworkPeering(destination)
}

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

var _ admission.Defaulter = &VirtualNetworksVirtualNetworkPeering{}

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

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

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

var _ genruntime.ImportableResource = &VirtualNetworksVirtualNetworkPeering{}

// InitializeSpec initializes the spec for this resource from the given status
func (peering *VirtualNetworksVirtualNetworkPeering) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*VirtualNetworks_VirtualNetworkPeering_STATUS); ok {
		return peering.Spec.Initialize_From_VirtualNetworks_VirtualNetworkPeering_STATUS(s)
	}

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

var _ genruntime.KubernetesResource = &VirtualNetworksVirtualNetworkPeering{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2020-11-01"
func (peering VirtualNetworksVirtualNetworkPeering) GetAPIVersion() string {
	return string(APIVersion_Value)
}

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

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

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

// GetSupportedOperations returns the operations supported by the resource
func (peering *VirtualNetworksVirtualNetworkPeering) 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/virtualNetworks/virtualNetworkPeerings"
func (peering *VirtualNetworksVirtualNetworkPeering) GetType() string {
	return "Microsoft.Network/virtualNetworks/virtualNetworkPeerings"
}

// NewEmptyStatus returns a new empty (blank) status
func (peering *VirtualNetworksVirtualNetworkPeering) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &VirtualNetworks_VirtualNetworkPeering_STATUS{}
}

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

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

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

	peering.Status = st
	return nil
}

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

var _ admission.Validator = &VirtualNetworksVirtualNetworkPeering{}

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

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

// ValidateUpdate validates an update of the resource
func (peering *VirtualNetworksVirtualNetworkPeering) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
	validations := peering.updateValidations()
	var temp any = peering
	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 (peering *VirtualNetworksVirtualNetworkPeering) createValidations() []func() (admission.Warnings, error) {
	return []func() (admission.Warnings, error){peering.validateResourceReferences, peering.validateOwnerReference}
}

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

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

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

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

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

	return genruntime.ValidateWriteOnceProperties(oldObj, peering)
}

// AssignProperties_From_VirtualNetworksVirtualNetworkPeering populates our VirtualNetworksVirtualNetworkPeering from the provided source VirtualNetworksVirtualNetworkPeering
func (peering *VirtualNetworksVirtualNetworkPeering) AssignProperties_From_VirtualNetworksVirtualNetworkPeering(source *v20201101s.VirtualNetworksVirtualNetworkPeering) error {

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

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

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

	// No error
	return nil
}

// AssignProperties_To_VirtualNetworksVirtualNetworkPeering populates the provided destination VirtualNetworksVirtualNetworkPeering from our VirtualNetworksVirtualNetworkPeering
func (peering *VirtualNetworksVirtualNetworkPeering) AssignProperties_To_VirtualNetworksVirtualNetworkPeering(destination *v20201101s.VirtualNetworksVirtualNetworkPeering) error {

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

	// Spec
	var spec v20201101s.VirtualNetworks_VirtualNetworkPeering_Spec
	err := peering.Spec.AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_Spec(&spec)
	if err != nil {
		return errors.Wrap(err, "calling AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_Spec() to populate field Spec")
	}
	destination.Spec = spec

	// Status
	var status v20201101s.VirtualNetworks_VirtualNetworkPeering_STATUS
	err = peering.Status.AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_STATUS(&status)
	if err != nil {
		return errors.Wrap(err, "calling AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_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 (peering *VirtualNetworksVirtualNetworkPeering) OriginalGVK() *schema.GroupVersionKind {
	return &schema.GroupVersionKind{
		Group:   GroupVersion.Group,
		Version: peering.Spec.OriginalVersion(),
		Kind:    "VirtualNetworksVirtualNetworkPeering",
	}
}

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /network/resource-manager/Microsoft.Network/stable/2020-11-01/virtualNetwork.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/virtualNetworkPeerings/{virtualNetworkPeeringName}
type VirtualNetworksVirtualNetworkPeeringList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []VirtualNetworksVirtualNetworkPeering `json:"items"`
}

type VirtualNetworks_VirtualNetworkPeering_Spec struct {
	// AllowForwardedTraffic: Whether the forwarded traffic from the VMs in the local virtual network will be
	// allowed/disallowed in remote virtual network.
	AllowForwardedTraffic *bool `json:"allowForwardedTraffic,omitempty"`

	// AllowGatewayTransit: If gateway links can be used in remote virtual networking to link to this virtual network.
	AllowGatewayTransit *bool `json:"allowGatewayTransit,omitempty"`

	// AllowVirtualNetworkAccess: Whether the VMs in the local virtual network space would be able to access the VMs in remote
	// virtual network space.
	AllowVirtualNetworkAccess *bool `json:"allowVirtualNetworkAccess,omitempty"`

	// 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"`

	// DoNotVerifyRemoteGateways: If we need to verify the provisioning state of the remote gateway.
	DoNotVerifyRemoteGateways *bool `json:"doNotVerifyRemoteGateways,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 network.azure.com/VirtualNetwork resource
	Owner *genruntime.KnownResourceReference `group:"network.azure.com" json:"owner,omitempty" kind:"VirtualNetwork"`

	// PeeringState: The status of the virtual network peering.
	PeeringState *VirtualNetworkPeeringPropertiesFormat_PeeringState `json:"peeringState,omitempty"`

	// RemoteAddressSpace: The reference to the remote virtual network address space.
	RemoteAddressSpace *AddressSpace `json:"remoteAddressSpace,omitempty"`

	// RemoteBgpCommunities: The reference to the remote virtual network's Bgp Communities.
	RemoteBgpCommunities *VirtualNetworkBgpCommunities `json:"remoteBgpCommunities,omitempty"`

	// RemoteVirtualNetwork: The reference to the remote virtual network. The remote virtual network can be in the same or
	// different region (preview). See here to register for the preview and learn more
	// (https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-create-peering).
	RemoteVirtualNetwork *SubResource `json:"remoteVirtualNetwork,omitempty"`

	// UseRemoteGateways: If remote gateways can be used on this virtual network. If the flag is set to true, and
	// allowGatewayTransit on remote peering is also true, virtual network will use gateways of remote virtual network for
	// transit. Only one peering can have this flag set to true. This flag cannot be set if virtual network already has a
	// gateway.
	UseRemoteGateways *bool `json:"useRemoteGateways,omitempty"`
}

var _ genruntime.ARMTransformer = &VirtualNetworks_VirtualNetworkPeering_Spec{}

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

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

	// Set property "Properties":
	if peering.AllowForwardedTraffic != nil ||
		peering.AllowGatewayTransit != nil ||
		peering.AllowVirtualNetworkAccess != nil ||
		peering.DoNotVerifyRemoteGateways != nil ||
		peering.PeeringState != nil ||
		peering.RemoteAddressSpace != nil ||
		peering.RemoteBgpCommunities != nil ||
		peering.RemoteVirtualNetwork != nil ||
		peering.UseRemoteGateways != nil {
		result.Properties = &VirtualNetworkPeeringPropertiesFormat_ARM{}
	}
	if peering.AllowForwardedTraffic != nil {
		allowForwardedTraffic := *peering.AllowForwardedTraffic
		result.Properties.AllowForwardedTraffic = &allowForwardedTraffic
	}
	if peering.AllowGatewayTransit != nil {
		allowGatewayTransit := *peering.AllowGatewayTransit
		result.Properties.AllowGatewayTransit = &allowGatewayTransit
	}
	if peering.AllowVirtualNetworkAccess != nil {
		allowVirtualNetworkAccess := *peering.AllowVirtualNetworkAccess
		result.Properties.AllowVirtualNetworkAccess = &allowVirtualNetworkAccess
	}
	if peering.DoNotVerifyRemoteGateways != nil {
		doNotVerifyRemoteGateways := *peering.DoNotVerifyRemoteGateways
		result.Properties.DoNotVerifyRemoteGateways = &doNotVerifyRemoteGateways
	}
	if peering.PeeringState != nil {
		peeringState := *peering.PeeringState
		result.Properties.PeeringState = &peeringState
	}
	if peering.RemoteAddressSpace != nil {
		remoteAddressSpace_ARM, err := (*peering.RemoteAddressSpace).ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		remoteAddressSpace := *remoteAddressSpace_ARM.(*AddressSpace_ARM)
		result.Properties.RemoteAddressSpace = &remoteAddressSpace
	}
	if peering.RemoteBgpCommunities != nil {
		remoteBgpCommunities_ARM, err := (*peering.RemoteBgpCommunities).ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		remoteBgpCommunities := *remoteBgpCommunities_ARM.(*VirtualNetworkBgpCommunities_ARM)
		result.Properties.RemoteBgpCommunities = &remoteBgpCommunities
	}
	if peering.RemoteVirtualNetwork != nil {
		remoteVirtualNetwork_ARM, err := (*peering.RemoteVirtualNetwork).ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		remoteVirtualNetwork := *remoteVirtualNetwork_ARM.(*SubResource_ARM)
		result.Properties.RemoteVirtualNetwork = &remoteVirtualNetwork
	}
	if peering.UseRemoteGateways != nil {
		useRemoteGateways := *peering.UseRemoteGateways
		result.Properties.UseRemoteGateways = &useRemoteGateways
	}
	return result, nil
}

// NewEmptyARMValue returns an empty ARM value suitable for deserializing into
func (peering *VirtualNetworks_VirtualNetworkPeering_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus {
	return &VirtualNetworks_VirtualNetworkPeering_Spec_ARM{}
}

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

	// Set property "AllowForwardedTraffic":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AllowForwardedTraffic != nil {
			allowForwardedTraffic := *typedInput.Properties.AllowForwardedTraffic
			peering.AllowForwardedTraffic = &allowForwardedTraffic
		}
	}

	// Set property "AllowGatewayTransit":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AllowGatewayTransit != nil {
			allowGatewayTransit := *typedInput.Properties.AllowGatewayTransit
			peering.AllowGatewayTransit = &allowGatewayTransit
		}
	}

	// Set property "AllowVirtualNetworkAccess":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AllowVirtualNetworkAccess != nil {
			allowVirtualNetworkAccess := *typedInput.Properties.AllowVirtualNetworkAccess
			peering.AllowVirtualNetworkAccess = &allowVirtualNetworkAccess
		}
	}

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

	// Set property "DoNotVerifyRemoteGateways":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.DoNotVerifyRemoteGateways != nil {
			doNotVerifyRemoteGateways := *typedInput.Properties.DoNotVerifyRemoteGateways
			peering.DoNotVerifyRemoteGateways = &doNotVerifyRemoteGateways
		}
	}

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

	// Set property "PeeringState":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.PeeringState != nil {
			peeringState := *typedInput.Properties.PeeringState
			peering.PeeringState = &peeringState
		}
	}

	// Set property "RemoteAddressSpace":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RemoteAddressSpace != nil {
			var remoteAddressSpace1 AddressSpace
			err := remoteAddressSpace1.PopulateFromARM(owner, *typedInput.Properties.RemoteAddressSpace)
			if err != nil {
				return err
			}
			remoteAddressSpace := remoteAddressSpace1
			peering.RemoteAddressSpace = &remoteAddressSpace
		}
	}

	// Set property "RemoteBgpCommunities":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RemoteBgpCommunities != nil {
			var remoteBgpCommunities1 VirtualNetworkBgpCommunities
			err := remoteBgpCommunities1.PopulateFromARM(owner, *typedInput.Properties.RemoteBgpCommunities)
			if err != nil {
				return err
			}
			remoteBgpCommunities := remoteBgpCommunities1
			peering.RemoteBgpCommunities = &remoteBgpCommunities
		}
	}

	// Set property "RemoteVirtualNetwork":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RemoteVirtualNetwork != nil {
			var remoteVirtualNetwork1 SubResource
			err := remoteVirtualNetwork1.PopulateFromARM(owner, *typedInput.Properties.RemoteVirtualNetwork)
			if err != nil {
				return err
			}
			remoteVirtualNetwork := remoteVirtualNetwork1
			peering.RemoteVirtualNetwork = &remoteVirtualNetwork
		}
	}

	// Set property "UseRemoteGateways":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.UseRemoteGateways != nil {
			useRemoteGateways := *typedInput.Properties.UseRemoteGateways
			peering.UseRemoteGateways = &useRemoteGateways
		}
	}

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &VirtualNetworks_VirtualNetworkPeering_Spec{}

// ConvertSpecFrom populates our VirtualNetworks_VirtualNetworkPeering_Spec from the provided source
func (peering *VirtualNetworks_VirtualNetworkPeering_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error {
	src, ok := source.(*v20201101s.VirtualNetworks_VirtualNetworkPeering_Spec)
	if ok {
		// Populate our instance from source
		return peering.AssignProperties_From_VirtualNetworks_VirtualNetworkPeering_Spec(src)
	}

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

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

	return nil
}

// ConvertSpecTo populates the provided destination from our VirtualNetworks_VirtualNetworkPeering_Spec
func (peering *VirtualNetworks_VirtualNetworkPeering_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error {
	dst, ok := destination.(*v20201101s.VirtualNetworks_VirtualNetworkPeering_Spec)
	if ok {
		// Populate destination from our instance
		return peering.AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_Spec(dst)
	}

	// Convert to an intermediate form
	dst = &v20201101s.VirtualNetworks_VirtualNetworkPeering_Spec{}
	err := peering.AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_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_VirtualNetworks_VirtualNetworkPeering_Spec populates our VirtualNetworks_VirtualNetworkPeering_Spec from the provided source VirtualNetworks_VirtualNetworkPeering_Spec
func (peering *VirtualNetworks_VirtualNetworkPeering_Spec) AssignProperties_From_VirtualNetworks_VirtualNetworkPeering_Spec(source *v20201101s.VirtualNetworks_VirtualNetworkPeering_Spec) error {

	// AllowForwardedTraffic
	if source.AllowForwardedTraffic != nil {
		allowForwardedTraffic := *source.AllowForwardedTraffic
		peering.AllowForwardedTraffic = &allowForwardedTraffic
	} else {
		peering.AllowForwardedTraffic = nil
	}

	// AllowGatewayTransit
	if source.AllowGatewayTransit != nil {
		allowGatewayTransit := *source.AllowGatewayTransit
		peering.AllowGatewayTransit = &allowGatewayTransit
	} else {
		peering.AllowGatewayTransit = nil
	}

	// AllowVirtualNetworkAccess
	if source.AllowVirtualNetworkAccess != nil {
		allowVirtualNetworkAccess := *source.AllowVirtualNetworkAccess
		peering.AllowVirtualNetworkAccess = &allowVirtualNetworkAccess
	} else {
		peering.AllowVirtualNetworkAccess = nil
	}

	// AzureName
	peering.AzureName = source.AzureName

	// DoNotVerifyRemoteGateways
	if source.DoNotVerifyRemoteGateways != nil {
		doNotVerifyRemoteGateway := *source.DoNotVerifyRemoteGateways
		peering.DoNotVerifyRemoteGateways = &doNotVerifyRemoteGateway
	} else {
		peering.DoNotVerifyRemoteGateways = nil
	}

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

	// PeeringState
	if source.PeeringState != nil {
		peeringState := VirtualNetworkPeeringPropertiesFormat_PeeringState(*source.PeeringState)
		peering.PeeringState = &peeringState
	} else {
		peering.PeeringState = nil
	}

	// RemoteAddressSpace
	if source.RemoteAddressSpace != nil {
		var remoteAddressSpace AddressSpace
		err := remoteAddressSpace.AssignProperties_From_AddressSpace(source.RemoteAddressSpace)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_From_AddressSpace() to populate field RemoteAddressSpace")
		}
		peering.RemoteAddressSpace = &remoteAddressSpace
	} else {
		peering.RemoteAddressSpace = nil
	}

	// RemoteBgpCommunities
	if source.RemoteBgpCommunities != nil {
		var remoteBgpCommunity VirtualNetworkBgpCommunities
		err := remoteBgpCommunity.AssignProperties_From_VirtualNetworkBgpCommunities(source.RemoteBgpCommunities)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_From_VirtualNetworkBgpCommunities() to populate field RemoteBgpCommunities")
		}
		peering.RemoteBgpCommunities = &remoteBgpCommunity
	} else {
		peering.RemoteBgpCommunities = nil
	}

	// RemoteVirtualNetwork
	if source.RemoteVirtualNetwork != nil {
		var remoteVirtualNetwork SubResource
		err := remoteVirtualNetwork.AssignProperties_From_SubResource(source.RemoteVirtualNetwork)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_From_SubResource() to populate field RemoteVirtualNetwork")
		}
		peering.RemoteVirtualNetwork = &remoteVirtualNetwork
	} else {
		peering.RemoteVirtualNetwork = nil
	}

	// UseRemoteGateways
	if source.UseRemoteGateways != nil {
		useRemoteGateway := *source.UseRemoteGateways
		peering.UseRemoteGateways = &useRemoteGateway
	} else {
		peering.UseRemoteGateways = nil
	}

	// No error
	return nil
}

// AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_Spec populates the provided destination VirtualNetworks_VirtualNetworkPeering_Spec from our VirtualNetworks_VirtualNetworkPeering_Spec
func (peering *VirtualNetworks_VirtualNetworkPeering_Spec) AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_Spec(destination *v20201101s.VirtualNetworks_VirtualNetworkPeering_Spec) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// AllowForwardedTraffic
	if peering.AllowForwardedTraffic != nil {
		allowForwardedTraffic := *peering.AllowForwardedTraffic
		destination.AllowForwardedTraffic = &allowForwardedTraffic
	} else {
		destination.AllowForwardedTraffic = nil
	}

	// AllowGatewayTransit
	if peering.AllowGatewayTransit != nil {
		allowGatewayTransit := *peering.AllowGatewayTransit
		destination.AllowGatewayTransit = &allowGatewayTransit
	} else {
		destination.AllowGatewayTransit = nil
	}

	// AllowVirtualNetworkAccess
	if peering.AllowVirtualNetworkAccess != nil {
		allowVirtualNetworkAccess := *peering.AllowVirtualNetworkAccess
		destination.AllowVirtualNetworkAccess = &allowVirtualNetworkAccess
	} else {
		destination.AllowVirtualNetworkAccess = nil
	}

	// AzureName
	destination.AzureName = peering.AzureName

	// DoNotVerifyRemoteGateways
	if peering.DoNotVerifyRemoteGateways != nil {
		doNotVerifyRemoteGateway := *peering.DoNotVerifyRemoteGateways
		destination.DoNotVerifyRemoteGateways = &doNotVerifyRemoteGateway
	} else {
		destination.DoNotVerifyRemoteGateways = nil
	}

	// OriginalVersion
	destination.OriginalVersion = peering.OriginalVersion()

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

	// PeeringState
	if peering.PeeringState != nil {
		peeringState := string(*peering.PeeringState)
		destination.PeeringState = &peeringState
	} else {
		destination.PeeringState = nil
	}

	// RemoteAddressSpace
	if peering.RemoteAddressSpace != nil {
		var remoteAddressSpace v20201101s.AddressSpace
		err := peering.RemoteAddressSpace.AssignProperties_To_AddressSpace(&remoteAddressSpace)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_To_AddressSpace() to populate field RemoteAddressSpace")
		}
		destination.RemoteAddressSpace = &remoteAddressSpace
	} else {
		destination.RemoteAddressSpace = nil
	}

	// RemoteBgpCommunities
	if peering.RemoteBgpCommunities != nil {
		var remoteBgpCommunity v20201101s.VirtualNetworkBgpCommunities
		err := peering.RemoteBgpCommunities.AssignProperties_To_VirtualNetworkBgpCommunities(&remoteBgpCommunity)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_To_VirtualNetworkBgpCommunities() to populate field RemoteBgpCommunities")
		}
		destination.RemoteBgpCommunities = &remoteBgpCommunity
	} else {
		destination.RemoteBgpCommunities = nil
	}

	// RemoteVirtualNetwork
	if peering.RemoteVirtualNetwork != nil {
		var remoteVirtualNetwork v20201101s.SubResource
		err := peering.RemoteVirtualNetwork.AssignProperties_To_SubResource(&remoteVirtualNetwork)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_To_SubResource() to populate field RemoteVirtualNetwork")
		}
		destination.RemoteVirtualNetwork = &remoteVirtualNetwork
	} else {
		destination.RemoteVirtualNetwork = nil
	}

	// UseRemoteGateways
	if peering.UseRemoteGateways != nil {
		useRemoteGateway := *peering.UseRemoteGateways
		destination.UseRemoteGateways = &useRemoteGateway
	} else {
		destination.UseRemoteGateways = nil
	}

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

	// No error
	return nil
}

// Initialize_From_VirtualNetworks_VirtualNetworkPeering_STATUS populates our VirtualNetworks_VirtualNetworkPeering_Spec from the provided source VirtualNetworks_VirtualNetworkPeering_STATUS
func (peering *VirtualNetworks_VirtualNetworkPeering_Spec) Initialize_From_VirtualNetworks_VirtualNetworkPeering_STATUS(source *VirtualNetworks_VirtualNetworkPeering_STATUS) error {

	// AllowForwardedTraffic
	if source.AllowForwardedTraffic != nil {
		allowForwardedTraffic := *source.AllowForwardedTraffic
		peering.AllowForwardedTraffic = &allowForwardedTraffic
	} else {
		peering.AllowForwardedTraffic = nil
	}

	// AllowGatewayTransit
	if source.AllowGatewayTransit != nil {
		allowGatewayTransit := *source.AllowGatewayTransit
		peering.AllowGatewayTransit = &allowGatewayTransit
	} else {
		peering.AllowGatewayTransit = nil
	}

	// AllowVirtualNetworkAccess
	if source.AllowVirtualNetworkAccess != nil {
		allowVirtualNetworkAccess := *source.AllowVirtualNetworkAccess
		peering.AllowVirtualNetworkAccess = &allowVirtualNetworkAccess
	} else {
		peering.AllowVirtualNetworkAccess = nil
	}

	// DoNotVerifyRemoteGateways
	if source.DoNotVerifyRemoteGateways != nil {
		doNotVerifyRemoteGateway := *source.DoNotVerifyRemoteGateways
		peering.DoNotVerifyRemoteGateways = &doNotVerifyRemoteGateway
	} else {
		peering.DoNotVerifyRemoteGateways = nil
	}

	// PeeringState
	if source.PeeringState != nil {
		peeringState := VirtualNetworkPeeringPropertiesFormat_PeeringState(*source.PeeringState)
		peering.PeeringState = &peeringState
	} else {
		peering.PeeringState = nil
	}

	// RemoteAddressSpace
	if source.RemoteAddressSpace != nil {
		var remoteAddressSpace AddressSpace
		err := remoteAddressSpace.Initialize_From_AddressSpace_STATUS(source.RemoteAddressSpace)
		if err != nil {
			return errors.Wrap(err, "calling Initialize_From_AddressSpace_STATUS() to populate field RemoteAddressSpace")
		}
		peering.RemoteAddressSpace = &remoteAddressSpace
	} else {
		peering.RemoteAddressSpace = nil
	}

	// RemoteBgpCommunities
	if source.RemoteBgpCommunities != nil {
		var remoteBgpCommunity VirtualNetworkBgpCommunities
		err := remoteBgpCommunity.Initialize_From_VirtualNetworkBgpCommunities_STATUS(source.RemoteBgpCommunities)
		if err != nil {
			return errors.Wrap(err, "calling Initialize_From_VirtualNetworkBgpCommunities_STATUS() to populate field RemoteBgpCommunities")
		}
		peering.RemoteBgpCommunities = &remoteBgpCommunity
	} else {
		peering.RemoteBgpCommunities = nil
	}

	// RemoteVirtualNetwork
	if source.RemoteVirtualNetwork != nil {
		var remoteVirtualNetwork SubResource
		err := remoteVirtualNetwork.Initialize_From_SubResource_STATUS(source.RemoteVirtualNetwork)
		if err != nil {
			return errors.Wrap(err, "calling Initialize_From_SubResource_STATUS() to populate field RemoteVirtualNetwork")
		}
		peering.RemoteVirtualNetwork = &remoteVirtualNetwork
	} else {
		peering.RemoteVirtualNetwork = nil
	}

	// UseRemoteGateways
	if source.UseRemoteGateways != nil {
		useRemoteGateway := *source.UseRemoteGateways
		peering.UseRemoteGateways = &useRemoteGateway
	} else {
		peering.UseRemoteGateways = nil
	}

	// No error
	return nil
}

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

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

type VirtualNetworks_VirtualNetworkPeering_STATUS struct {
	// AllowForwardedTraffic: Whether the forwarded traffic from the VMs in the local virtual network will be
	// allowed/disallowed in remote virtual network.
	AllowForwardedTraffic *bool `json:"allowForwardedTraffic,omitempty"`

	// AllowGatewayTransit: If gateway links can be used in remote virtual networking to link to this virtual network.
	AllowGatewayTransit *bool `json:"allowGatewayTransit,omitempty"`

	// AllowVirtualNetworkAccess: Whether the VMs in the local virtual network space would be able to access the VMs in remote
	// virtual network space.
	AllowVirtualNetworkAccess *bool `json:"allowVirtualNetworkAccess,omitempty"`

	// Conditions: The observed state of the resource
	Conditions []conditions.Condition `json:"conditions,omitempty"`

	// DoNotVerifyRemoteGateways: If we need to verify the provisioning state of the remote gateway.
	DoNotVerifyRemoteGateways *bool `json:"doNotVerifyRemoteGateways,omitempty"`

	// Etag: A unique read-only string that changes whenever the resource is updated.
	Etag *string `json:"etag,omitempty"`

	// Id: Resource ID.
	Id *string `json:"id,omitempty"`

	// Name: The name of the resource that is unique within a resource group. This name can be used to access the resource.
	Name *string `json:"name,omitempty"`

	// PeeringState: The status of the virtual network peering.
	PeeringState *VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS `json:"peeringState,omitempty"`

	// ProvisioningState: The provisioning state of the virtual network peering resource.
	ProvisioningState *ProvisioningState_STATUS `json:"provisioningState,omitempty"`

	// RemoteAddressSpace: The reference to the remote virtual network address space.
	RemoteAddressSpace *AddressSpace_STATUS `json:"remoteAddressSpace,omitempty"`

	// RemoteBgpCommunities: The reference to the remote virtual network's Bgp Communities.
	RemoteBgpCommunities *VirtualNetworkBgpCommunities_STATUS `json:"remoteBgpCommunities,omitempty"`

	// RemoteVirtualNetwork: The reference to the remote virtual network. The remote virtual network can be in the same or
	// different region (preview). See here to register for the preview and learn more
	// (https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-create-peering).
	RemoteVirtualNetwork *SubResource_STATUS `json:"remoteVirtualNetwork,omitempty"`

	// ResourceGuid: The resourceGuid property of the Virtual Network peering resource.
	ResourceGuid *string `json:"resourceGuid,omitempty"`

	// Type: Resource type.
	Type *string `json:"type,omitempty"`

	// UseRemoteGateways: If remote gateways can be used on this virtual network. If the flag is set to true, and
	// allowGatewayTransit on remote peering is also true, virtual network will use gateways of remote virtual network for
	// transit. Only one peering can have this flag set to true. This flag cannot be set if virtual network already has a
	// gateway.
	UseRemoteGateways *bool `json:"useRemoteGateways,omitempty"`
}

var _ genruntime.ConvertibleStatus = &VirtualNetworks_VirtualNetworkPeering_STATUS{}

// ConvertStatusFrom populates our VirtualNetworks_VirtualNetworkPeering_STATUS from the provided source
func (peering *VirtualNetworks_VirtualNetworkPeering_STATUS) ConvertStatusFrom(source genruntime.ConvertibleStatus) error {
	src, ok := source.(*v20201101s.VirtualNetworks_VirtualNetworkPeering_STATUS)
	if ok {
		// Populate our instance from source
		return peering.AssignProperties_From_VirtualNetworks_VirtualNetworkPeering_STATUS(src)
	}

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

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

	return nil
}

// ConvertStatusTo populates the provided destination from our VirtualNetworks_VirtualNetworkPeering_STATUS
func (peering *VirtualNetworks_VirtualNetworkPeering_STATUS) ConvertStatusTo(destination genruntime.ConvertibleStatus) error {
	dst, ok := destination.(*v20201101s.VirtualNetworks_VirtualNetworkPeering_STATUS)
	if ok {
		// Populate destination from our instance
		return peering.AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_STATUS(dst)
	}

	// Convert to an intermediate form
	dst = &v20201101s.VirtualNetworks_VirtualNetworkPeering_STATUS{}
	err := peering.AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_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 = &VirtualNetworks_VirtualNetworkPeering_STATUS{}

// NewEmptyARMValue returns an empty ARM value suitable for deserializing into
func (peering *VirtualNetworks_VirtualNetworkPeering_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus {
	return &VirtualNetworks_VirtualNetworkPeering_STATUS_ARM{}
}

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

	// Set property "AllowForwardedTraffic":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AllowForwardedTraffic != nil {
			allowForwardedTraffic := *typedInput.Properties.AllowForwardedTraffic
			peering.AllowForwardedTraffic = &allowForwardedTraffic
		}
	}

	// Set property "AllowGatewayTransit":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AllowGatewayTransit != nil {
			allowGatewayTransit := *typedInput.Properties.AllowGatewayTransit
			peering.AllowGatewayTransit = &allowGatewayTransit
		}
	}

	// Set property "AllowVirtualNetworkAccess":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AllowVirtualNetworkAccess != nil {
			allowVirtualNetworkAccess := *typedInput.Properties.AllowVirtualNetworkAccess
			peering.AllowVirtualNetworkAccess = &allowVirtualNetworkAccess
		}
	}

	// no assignment for property "Conditions"

	// Set property "DoNotVerifyRemoteGateways":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.DoNotVerifyRemoteGateways != nil {
			doNotVerifyRemoteGateways := *typedInput.Properties.DoNotVerifyRemoteGateways
			peering.DoNotVerifyRemoteGateways = &doNotVerifyRemoteGateways
		}
	}

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

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

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

	// Set property "PeeringState":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.PeeringState != nil {
			peeringState := *typedInput.Properties.PeeringState
			peering.PeeringState = &peeringState
		}
	}

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

	// Set property "RemoteAddressSpace":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RemoteAddressSpace != nil {
			var remoteAddressSpace1 AddressSpace_STATUS
			err := remoteAddressSpace1.PopulateFromARM(owner, *typedInput.Properties.RemoteAddressSpace)
			if err != nil {
				return err
			}
			remoteAddressSpace := remoteAddressSpace1
			peering.RemoteAddressSpace = &remoteAddressSpace
		}
	}

	// Set property "RemoteBgpCommunities":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RemoteBgpCommunities != nil {
			var remoteBgpCommunities1 VirtualNetworkBgpCommunities_STATUS
			err := remoteBgpCommunities1.PopulateFromARM(owner, *typedInput.Properties.RemoteBgpCommunities)
			if err != nil {
				return err
			}
			remoteBgpCommunities := remoteBgpCommunities1
			peering.RemoteBgpCommunities = &remoteBgpCommunities
		}
	}

	// Set property "RemoteVirtualNetwork":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RemoteVirtualNetwork != nil {
			var remoteVirtualNetwork1 SubResource_STATUS
			err := remoteVirtualNetwork1.PopulateFromARM(owner, *typedInput.Properties.RemoteVirtualNetwork)
			if err != nil {
				return err
			}
			remoteVirtualNetwork := remoteVirtualNetwork1
			peering.RemoteVirtualNetwork = &remoteVirtualNetwork
		}
	}

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

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

	// Set property "UseRemoteGateways":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.UseRemoteGateways != nil {
			useRemoteGateways := *typedInput.Properties.UseRemoteGateways
			peering.UseRemoteGateways = &useRemoteGateways
		}
	}

	// No error
	return nil
}

// AssignProperties_From_VirtualNetworks_VirtualNetworkPeering_STATUS populates our VirtualNetworks_VirtualNetworkPeering_STATUS from the provided source VirtualNetworks_VirtualNetworkPeering_STATUS
func (peering *VirtualNetworks_VirtualNetworkPeering_STATUS) AssignProperties_From_VirtualNetworks_VirtualNetworkPeering_STATUS(source *v20201101s.VirtualNetworks_VirtualNetworkPeering_STATUS) error {

	// AllowForwardedTraffic
	if source.AllowForwardedTraffic != nil {
		allowForwardedTraffic := *source.AllowForwardedTraffic
		peering.AllowForwardedTraffic = &allowForwardedTraffic
	} else {
		peering.AllowForwardedTraffic = nil
	}

	// AllowGatewayTransit
	if source.AllowGatewayTransit != nil {
		allowGatewayTransit := *source.AllowGatewayTransit
		peering.AllowGatewayTransit = &allowGatewayTransit
	} else {
		peering.AllowGatewayTransit = nil
	}

	// AllowVirtualNetworkAccess
	if source.AllowVirtualNetworkAccess != nil {
		allowVirtualNetworkAccess := *source.AllowVirtualNetworkAccess
		peering.AllowVirtualNetworkAccess = &allowVirtualNetworkAccess
	} else {
		peering.AllowVirtualNetworkAccess = nil
	}

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

	// DoNotVerifyRemoteGateways
	if source.DoNotVerifyRemoteGateways != nil {
		doNotVerifyRemoteGateway := *source.DoNotVerifyRemoteGateways
		peering.DoNotVerifyRemoteGateways = &doNotVerifyRemoteGateway
	} else {
		peering.DoNotVerifyRemoteGateways = nil
	}

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

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

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

	// PeeringState
	if source.PeeringState != nil {
		peeringState := VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS(*source.PeeringState)
		peering.PeeringState = &peeringState
	} else {
		peering.PeeringState = nil
	}

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

	// RemoteAddressSpace
	if source.RemoteAddressSpace != nil {
		var remoteAddressSpace AddressSpace_STATUS
		err := remoteAddressSpace.AssignProperties_From_AddressSpace_STATUS(source.RemoteAddressSpace)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_From_AddressSpace_STATUS() to populate field RemoteAddressSpace")
		}
		peering.RemoteAddressSpace = &remoteAddressSpace
	} else {
		peering.RemoteAddressSpace = nil
	}

	// RemoteBgpCommunities
	if source.RemoteBgpCommunities != nil {
		var remoteBgpCommunity VirtualNetworkBgpCommunities_STATUS
		err := remoteBgpCommunity.AssignProperties_From_VirtualNetworkBgpCommunities_STATUS(source.RemoteBgpCommunities)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_From_VirtualNetworkBgpCommunities_STATUS() to populate field RemoteBgpCommunities")
		}
		peering.RemoteBgpCommunities = &remoteBgpCommunity
	} else {
		peering.RemoteBgpCommunities = nil
	}

	// RemoteVirtualNetwork
	if source.RemoteVirtualNetwork != nil {
		var remoteVirtualNetwork SubResource_STATUS
		err := remoteVirtualNetwork.AssignProperties_From_SubResource_STATUS(source.RemoteVirtualNetwork)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_From_SubResource_STATUS() to populate field RemoteVirtualNetwork")
		}
		peering.RemoteVirtualNetwork = &remoteVirtualNetwork
	} else {
		peering.RemoteVirtualNetwork = nil
	}

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

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

	// UseRemoteGateways
	if source.UseRemoteGateways != nil {
		useRemoteGateway := *source.UseRemoteGateways
		peering.UseRemoteGateways = &useRemoteGateway
	} else {
		peering.UseRemoteGateways = nil
	}

	// No error
	return nil
}

// AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_STATUS populates the provided destination VirtualNetworks_VirtualNetworkPeering_STATUS from our VirtualNetworks_VirtualNetworkPeering_STATUS
func (peering *VirtualNetworks_VirtualNetworkPeering_STATUS) AssignProperties_To_VirtualNetworks_VirtualNetworkPeering_STATUS(destination *v20201101s.VirtualNetworks_VirtualNetworkPeering_STATUS) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// AllowForwardedTraffic
	if peering.AllowForwardedTraffic != nil {
		allowForwardedTraffic := *peering.AllowForwardedTraffic
		destination.AllowForwardedTraffic = &allowForwardedTraffic
	} else {
		destination.AllowForwardedTraffic = nil
	}

	// AllowGatewayTransit
	if peering.AllowGatewayTransit != nil {
		allowGatewayTransit := *peering.AllowGatewayTransit
		destination.AllowGatewayTransit = &allowGatewayTransit
	} else {
		destination.AllowGatewayTransit = nil
	}

	// AllowVirtualNetworkAccess
	if peering.AllowVirtualNetworkAccess != nil {
		allowVirtualNetworkAccess := *peering.AllowVirtualNetworkAccess
		destination.AllowVirtualNetworkAccess = &allowVirtualNetworkAccess
	} else {
		destination.AllowVirtualNetworkAccess = nil
	}

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

	// DoNotVerifyRemoteGateways
	if peering.DoNotVerifyRemoteGateways != nil {
		doNotVerifyRemoteGateway := *peering.DoNotVerifyRemoteGateways
		destination.DoNotVerifyRemoteGateways = &doNotVerifyRemoteGateway
	} else {
		destination.DoNotVerifyRemoteGateways = nil
	}

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

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

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

	// PeeringState
	if peering.PeeringState != nil {
		peeringState := string(*peering.PeeringState)
		destination.PeeringState = &peeringState
	} else {
		destination.PeeringState = nil
	}

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

	// RemoteAddressSpace
	if peering.RemoteAddressSpace != nil {
		var remoteAddressSpace v20201101s.AddressSpace_STATUS
		err := peering.RemoteAddressSpace.AssignProperties_To_AddressSpace_STATUS(&remoteAddressSpace)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_To_AddressSpace_STATUS() to populate field RemoteAddressSpace")
		}
		destination.RemoteAddressSpace = &remoteAddressSpace
	} else {
		destination.RemoteAddressSpace = nil
	}

	// RemoteBgpCommunities
	if peering.RemoteBgpCommunities != nil {
		var remoteBgpCommunity v20201101s.VirtualNetworkBgpCommunities_STATUS
		err := peering.RemoteBgpCommunities.AssignProperties_To_VirtualNetworkBgpCommunities_STATUS(&remoteBgpCommunity)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_To_VirtualNetworkBgpCommunities_STATUS() to populate field RemoteBgpCommunities")
		}
		destination.RemoteBgpCommunities = &remoteBgpCommunity
	} else {
		destination.RemoteBgpCommunities = nil
	}

	// RemoteVirtualNetwork
	if peering.RemoteVirtualNetwork != nil {
		var remoteVirtualNetwork v20201101s.SubResource_STATUS
		err := peering.RemoteVirtualNetwork.AssignProperties_To_SubResource_STATUS(&remoteVirtualNetwork)
		if err != nil {
			return errors.Wrap(err, "calling AssignProperties_To_SubResource_STATUS() to populate field RemoteVirtualNetwork")
		}
		destination.RemoteVirtualNetwork = &remoteVirtualNetwork
	} else {
		destination.RemoteVirtualNetwork = nil
	}

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

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

	// UseRemoteGateways
	if peering.UseRemoteGateways != nil {
		useRemoteGateway := *peering.UseRemoteGateways
		destination.UseRemoteGateways = &useRemoteGateway
	} else {
		destination.UseRemoteGateways = nil
	}

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

	// No error
	return nil
}

// +kubebuilder:validation:Enum={"Connected","Disconnected","Initiated"}
type VirtualNetworkPeeringPropertiesFormat_PeeringState string

const (
	VirtualNetworkPeeringPropertiesFormat_PeeringState_Connected    = VirtualNetworkPeeringPropertiesFormat_PeeringState("Connected")
	VirtualNetworkPeeringPropertiesFormat_PeeringState_Disconnected = VirtualNetworkPeeringPropertiesFormat_PeeringState("Disconnected")
	VirtualNetworkPeeringPropertiesFormat_PeeringState_Initiated    = VirtualNetworkPeeringPropertiesFormat_PeeringState("Initiated")
)

type VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS string

const (
	VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS_Connected    = VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS("Connected")
	VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS_Disconnected = VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS("Disconnected")
	VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS_Initiated    = VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS("Initiated")
)

func init() {
	SchemeBuilder.Register(&VirtualNetworksVirtualNetworkPeering{}, &VirtualNetworksVirtualNetworkPeeringList{})
}
