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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101/storage"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime/configmaps"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime/core"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime/secrets"
	"github.com/rotisserie/eris"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"sigs.k8s.io/controller-runtime/pkg/conversion"
)

// +kubebuilder:object:root=true
// +kubebuilder:resource:categories={azure,network}
// +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              VirtualNetworksVirtualNetworkPeering_Spec   `json:"spec,omitempty"`
	Status            VirtualNetworksVirtualNetworkPeering_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 {
	// intermediate variable for conversion
	var source storage.VirtualNetworksVirtualNetworkPeering

	err := source.ConvertFrom(hub)
	if err != nil {
		return eris.Wrap(err, "converting from hub to source")
	}

	err = peering.AssignProperties_From_VirtualNetworksVirtualNetworkPeering(&source)
	if err != nil {
		return eris.Wrap(err, "converting from source to peering")
	}

	return nil
}

// ConvertTo populates the provided hub VirtualNetworksVirtualNetworkPeering from our VirtualNetworksVirtualNetworkPeering
func (peering *VirtualNetworksVirtualNetworkPeering) ConvertTo(hub conversion.Hub) error {
	// intermediate variable for conversion
	var destination storage.VirtualNetworksVirtualNetworkPeering
	err := peering.AssignProperties_To_VirtualNetworksVirtualNetworkPeering(&destination)
	if err != nil {
		return eris.Wrap(err, "converting to destination from peering")
	}
	err = destination.ConvertTo(hub)
	if err != nil {
		return eris.Wrap(err, "converting from destination to hub")
	}

	return nil
}

var _ configmaps.Exporter = &VirtualNetworksVirtualNetworkPeering{}

// ConfigMapDestinationExpressions returns the Spec.OperatorSpec.ConfigMapExpressions property
func (peering *VirtualNetworksVirtualNetworkPeering) ConfigMapDestinationExpressions() []*core.DestinationExpression {
	if peering.Spec.OperatorSpec == nil {
		return nil
	}
	return peering.Spec.OperatorSpec.ConfigMapExpressions
}

var _ secrets.Exporter = &VirtualNetworksVirtualNetworkPeering{}

// SecretDestinationExpressions returns the Spec.OperatorSpec.SecretExpressions property
func (peering *VirtualNetworksVirtualNetworkPeering) SecretDestinationExpressions() []*core.DestinationExpression {
	if peering.Spec.OperatorSpec == nil {
		return nil
	}
	return peering.Spec.OperatorSpec.SecretExpressions
}

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 "2020-11-01"
}

// 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 &VirtualNetworksVirtualNetworkPeering_STATUS{}
}

// Owner returns the ResourceReference of the owner
func (peering *VirtualNetworksVirtualNetworkPeering) Owner() *genruntime.ResourceReference {
	if peering.Spec.Owner == nil {
		return nil
	}

	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.(*VirtualNetworksVirtualNetworkPeering_STATUS); ok {
		peering.Status = *st
		return nil
	}

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

	peering.Status = st
	return nil
}

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

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

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

	// Status
	var status VirtualNetworksVirtualNetworkPeering_STATUS
	err = status.AssignProperties_From_VirtualNetworksVirtualNetworkPeering_STATUS(&source.Status)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_From_VirtualNetworksVirtualNetworkPeering_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 *storage.VirtualNetworksVirtualNetworkPeering) error {

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

	// Spec
	var spec storage.VirtualNetworksVirtualNetworkPeering_Spec
	err := peering.Spec.AssignProperties_To_VirtualNetworksVirtualNetworkPeering_Spec(&spec)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_To_VirtualNetworksVirtualNetworkPeering_Spec() to populate field Spec")
	}
	destination.Spec = spec

	// Status
	var status storage.VirtualNetworksVirtualNetworkPeering_STATUS
	err = peering.Status.AssignProperties_To_VirtualNetworksVirtualNetworkPeering_STATUS(&status)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_To_VirtualNetworksVirtualNetworkPeering_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 VirtualNetworksVirtualNetworkPeering_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"`

	// OperatorSpec: The specification for configuring operator behavior. This field is interpreted by the operator and not
	// passed directly to Azure
	OperatorSpec *VirtualNetworksVirtualNetworkPeeringOperatorSpec `json:"operatorSpec,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 = &VirtualNetworksVirtualNetworkPeering_Spec{}

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

	// 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 = &arm.VirtualNetworkPeeringPropertiesFormat{}
	}
	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 {
		var temp string
		temp = string(*peering.PeeringState)
		peeringState := arm.VirtualNetworkPeeringPropertiesFormat_PeeringState(temp)
		result.Properties.PeeringState = &peeringState
	}
	if peering.RemoteAddressSpace != nil {
		remoteAddressSpace_ARM, err := peering.RemoteAddressSpace.ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		remoteAddressSpace := *remoteAddressSpace_ARM.(*arm.AddressSpace)
		result.Properties.RemoteAddressSpace = &remoteAddressSpace
	}
	if peering.RemoteBgpCommunities != nil {
		remoteBgpCommunities_ARM, err := peering.RemoteBgpCommunities.ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		remoteBgpCommunities := *remoteBgpCommunities_ARM.(*arm.VirtualNetworkBgpCommunities)
		result.Properties.RemoteBgpCommunities = &remoteBgpCommunities
	}
	if peering.RemoteVirtualNetwork != nil {
		remoteVirtualNetwork_ARM, err := peering.RemoteVirtualNetwork.ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		remoteVirtualNetwork := *remoteVirtualNetwork_ARM.(*arm.SubResource)
		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 *VirtualNetworksVirtualNetworkPeering_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus {
	return &arm.VirtualNetworksVirtualNetworkPeering_Spec{}
}

// PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object
func (peering *VirtualNetworksVirtualNetworkPeering_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error {
	typedInput, ok := armInput.(arm.VirtualNetworksVirtualNetworkPeering_Spec)
	if !ok {
		return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.VirtualNetworksVirtualNetworkPeering_Spec, 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
		}
	}

	// no assignment for property "OperatorSpec"

	// 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 {
			var temp string
			temp = string(*typedInput.Properties.PeeringState)
			peeringState := VirtualNetworkPeeringPropertiesFormat_PeeringState(temp)
			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 = &VirtualNetworksVirtualNetworkPeering_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.VirtualNetworksVirtualNetworkPeering_Spec{}
	err := peering.AssignProperties_To_VirtualNetworksVirtualNetworkPeering_Spec(dst)
	if err != nil {
		return eris.Wrap(err, "initial step of conversion in ConvertSpecTo()")
	}

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

	return nil
}

// AssignProperties_From_VirtualNetworksVirtualNetworkPeering_Spec populates our VirtualNetworksVirtualNetworkPeering_Spec from the provided source VirtualNetworksVirtualNetworkPeering_Spec
func (peering *VirtualNetworksVirtualNetworkPeering_Spec) AssignProperties_From_VirtualNetworksVirtualNetworkPeering_Spec(source *storage.VirtualNetworksVirtualNetworkPeering_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
	}

	// OperatorSpec
	if source.OperatorSpec != nil {
		var operatorSpec VirtualNetworksVirtualNetworkPeeringOperatorSpec
		err := operatorSpec.AssignProperties_From_VirtualNetworksVirtualNetworkPeeringOperatorSpec(source.OperatorSpec)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_VirtualNetworksVirtualNetworkPeeringOperatorSpec() to populate field OperatorSpec")
		}
		peering.OperatorSpec = &operatorSpec
	} else {
		peering.OperatorSpec = nil
	}

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

	// PeeringState
	if source.PeeringState != nil {
		peeringState := *source.PeeringState
		peeringStateTemp := genruntime.ToEnum(peeringState, virtualNetworkPeeringPropertiesFormat_PeeringState_Values)
		peering.PeeringState = &peeringStateTemp
	} else {
		peering.PeeringState = nil
	}

	// RemoteAddressSpace
	if source.RemoteAddressSpace != nil {
		var remoteAddressSpace AddressSpace
		err := remoteAddressSpace.AssignProperties_From_AddressSpace(source.RemoteAddressSpace)
		if err != nil {
			return eris.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 eris.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 eris.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_VirtualNetworksVirtualNetworkPeering_Spec populates the provided destination VirtualNetworksVirtualNetworkPeering_Spec from our VirtualNetworksVirtualNetworkPeering_Spec
func (peering *VirtualNetworksVirtualNetworkPeering_Spec) AssignProperties_To_VirtualNetworksVirtualNetworkPeering_Spec(destination *storage.VirtualNetworksVirtualNetworkPeering_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
	}

	// OperatorSpec
	if peering.OperatorSpec != nil {
		var operatorSpec storage.VirtualNetworksVirtualNetworkPeeringOperatorSpec
		err := peering.OperatorSpec.AssignProperties_To_VirtualNetworksVirtualNetworkPeeringOperatorSpec(&operatorSpec)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_VirtualNetworksVirtualNetworkPeeringOperatorSpec() to populate field OperatorSpec")
		}
		destination.OperatorSpec = &operatorSpec
	} else {
		destination.OperatorSpec = 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 storage.AddressSpace
		err := peering.RemoteAddressSpace.AssignProperties_To_AddressSpace(&remoteAddressSpace)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_AddressSpace() to populate field RemoteAddressSpace")
		}
		destination.RemoteAddressSpace = &remoteAddressSpace
	} else {
		destination.RemoteAddressSpace = nil
	}

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

	// RemoteVirtualNetwork
	if peering.RemoteVirtualNetwork != nil {
		var remoteVirtualNetwork storage.SubResource
		err := peering.RemoteVirtualNetwork.AssignProperties_To_SubResource(&remoteVirtualNetwork)
		if err != nil {
			return eris.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
}

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

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

type VirtualNetworksVirtualNetworkPeering_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 = &VirtualNetworksVirtualNetworkPeering_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.VirtualNetworksVirtualNetworkPeering_STATUS{}
	err := peering.AssignProperties_To_VirtualNetworksVirtualNetworkPeering_STATUS(dst)
	if err != nil {
		return eris.Wrap(err, "initial step of conversion in ConvertStatusTo()")
	}

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

	return nil
}

var _ genruntime.FromARMConverter = &VirtualNetworksVirtualNetworkPeering_STATUS{}

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

// PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object
func (peering *VirtualNetworksVirtualNetworkPeering_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error {
	typedInput, ok := armInput.(arm.VirtualNetworksVirtualNetworkPeering_STATUS)
	if !ok {
		return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.VirtualNetworksVirtualNetworkPeering_STATUS, 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 {
			var temp string
			temp = string(*typedInput.Properties.PeeringState)
			peeringState := VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS(temp)
			peering.PeeringState = &peeringState
		}
	}

	// Set property "ProvisioningState":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ProvisioningState != nil {
			var temp string
			temp = string(*typedInput.Properties.ProvisioningState)
			provisioningState := ProvisioningState_STATUS(temp)
			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_VirtualNetworksVirtualNetworkPeering_STATUS populates our VirtualNetworksVirtualNetworkPeering_STATUS from the provided source VirtualNetworksVirtualNetworkPeering_STATUS
func (peering *VirtualNetworksVirtualNetworkPeering_STATUS) AssignProperties_From_VirtualNetworksVirtualNetworkPeering_STATUS(source *storage.VirtualNetworksVirtualNetworkPeering_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 := *source.PeeringState
		peeringStateTemp := genruntime.ToEnum(peeringState, virtualNetworkPeeringPropertiesFormat_PeeringState_STATUS_Values)
		peering.PeeringState = &peeringStateTemp
	} else {
		peering.PeeringState = nil
	}

	// ProvisioningState
	if source.ProvisioningState != nil {
		provisioningState := *source.ProvisioningState
		provisioningStateTemp := genruntime.ToEnum(provisioningState, provisioningState_STATUS_Values)
		peering.ProvisioningState = &provisioningStateTemp
	} 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 eris.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 eris.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 eris.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_VirtualNetworksVirtualNetworkPeering_STATUS populates the provided destination VirtualNetworksVirtualNetworkPeering_STATUS from our VirtualNetworksVirtualNetworkPeering_STATUS
func (peering *VirtualNetworksVirtualNetworkPeering_STATUS) AssignProperties_To_VirtualNetworksVirtualNetworkPeering_STATUS(destination *storage.VirtualNetworksVirtualNetworkPeering_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 storage.AddressSpace_STATUS
		err := peering.RemoteAddressSpace.AssignProperties_To_AddressSpace_STATUS(&remoteAddressSpace)
		if err != nil {
			return eris.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 storage.VirtualNetworkBgpCommunities_STATUS
		err := peering.RemoteBgpCommunities.AssignProperties_To_VirtualNetworkBgpCommunities_STATUS(&remoteBgpCommunity)
		if err != nil {
			return eris.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 storage.SubResource_STATUS
		err := peering.RemoteVirtualNetwork.AssignProperties_To_SubResource_STATUS(&remoteVirtualNetwork)
		if err != nil {
			return eris.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")
)

// Mapping from string to VirtualNetworkPeeringPropertiesFormat_PeeringState
var virtualNetworkPeeringPropertiesFormat_PeeringState_Values = map[string]VirtualNetworkPeeringPropertiesFormat_PeeringState{
	"connected":    VirtualNetworkPeeringPropertiesFormat_PeeringState_Connected,
	"disconnected": VirtualNetworkPeeringPropertiesFormat_PeeringState_Disconnected,
	"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")
)

// Mapping from string to VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS
var virtualNetworkPeeringPropertiesFormat_PeeringState_STATUS_Values = map[string]VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS{
	"connected":    VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS_Connected,
	"disconnected": VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS_Disconnected,
	"initiated":    VirtualNetworkPeeringPropertiesFormat_PeeringState_STATUS_Initiated,
}

// Details for configuring operator behavior. Fields in this struct are interpreted by the operator directly rather than being passed to Azure
type VirtualNetworksVirtualNetworkPeeringOperatorSpec struct {
	// ConfigMapExpressions: configures where to place operator written dynamic ConfigMaps (created with CEL expressions).
	ConfigMapExpressions []*core.DestinationExpression `json:"configMapExpressions,omitempty"`

	// SecretExpressions: configures where to place operator written dynamic secrets (created with CEL expressions).
	SecretExpressions []*core.DestinationExpression `json:"secretExpressions,omitempty"`
}

// AssignProperties_From_VirtualNetworksVirtualNetworkPeeringOperatorSpec populates our VirtualNetworksVirtualNetworkPeeringOperatorSpec from the provided source VirtualNetworksVirtualNetworkPeeringOperatorSpec
func (operator *VirtualNetworksVirtualNetworkPeeringOperatorSpec) AssignProperties_From_VirtualNetworksVirtualNetworkPeeringOperatorSpec(source *storage.VirtualNetworksVirtualNetworkPeeringOperatorSpec) error {

	// ConfigMapExpressions
	if source.ConfigMapExpressions != nil {
		configMapExpressionList := make([]*core.DestinationExpression, len(source.ConfigMapExpressions))
		for configMapExpressionIndex, configMapExpressionItem := range source.ConfigMapExpressions {
			if configMapExpressionItem != nil {
				configMapExpression := *configMapExpressionItem.DeepCopy()
				configMapExpressionList[configMapExpressionIndex] = &configMapExpression
			} else {
				configMapExpressionList[configMapExpressionIndex] = nil
			}
		}
		operator.ConfigMapExpressions = configMapExpressionList
	} else {
		operator.ConfigMapExpressions = nil
	}

	// SecretExpressions
	if source.SecretExpressions != nil {
		secretExpressionList := make([]*core.DestinationExpression, len(source.SecretExpressions))
		for secretExpressionIndex, secretExpressionItem := range source.SecretExpressions {
			if secretExpressionItem != nil {
				secretExpression := *secretExpressionItem.DeepCopy()
				secretExpressionList[secretExpressionIndex] = &secretExpression
			} else {
				secretExpressionList[secretExpressionIndex] = nil
			}
		}
		operator.SecretExpressions = secretExpressionList
	} else {
		operator.SecretExpressions = nil
	}

	// No error
	return nil
}

// AssignProperties_To_VirtualNetworksVirtualNetworkPeeringOperatorSpec populates the provided destination VirtualNetworksVirtualNetworkPeeringOperatorSpec from our VirtualNetworksVirtualNetworkPeeringOperatorSpec
func (operator *VirtualNetworksVirtualNetworkPeeringOperatorSpec) AssignProperties_To_VirtualNetworksVirtualNetworkPeeringOperatorSpec(destination *storage.VirtualNetworksVirtualNetworkPeeringOperatorSpec) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// ConfigMapExpressions
	if operator.ConfigMapExpressions != nil {
		configMapExpressionList := make([]*core.DestinationExpression, len(operator.ConfigMapExpressions))
		for configMapExpressionIndex, configMapExpressionItem := range operator.ConfigMapExpressions {
			if configMapExpressionItem != nil {
				configMapExpression := *configMapExpressionItem.DeepCopy()
				configMapExpressionList[configMapExpressionIndex] = &configMapExpression
			} else {
				configMapExpressionList[configMapExpressionIndex] = nil
			}
		}
		destination.ConfigMapExpressions = configMapExpressionList
	} else {
		destination.ConfigMapExpressions = nil
	}

	// SecretExpressions
	if operator.SecretExpressions != nil {
		secretExpressionList := make([]*core.DestinationExpression, len(operator.SecretExpressions))
		for secretExpressionIndex, secretExpressionItem := range operator.SecretExpressions {
			if secretExpressionItem != nil {
				secretExpression := *secretExpressionItem.DeepCopy()
				secretExpressionList[secretExpressionIndex] = &secretExpression
			} else {
				secretExpressionList[secretExpressionIndex] = nil
			}
		}
		destination.SecretExpressions = secretExpressionList
	} else {
		destination.SecretExpressions = nil
	}

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

	// No error
	return nil
}

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