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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/compute/v1api20220301/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/compute/v1api20220301/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"
	"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
	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,compute}
// +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: /compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2022-03-01/virtualMachineScaleSet.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/extensions/{vmssExtensionName}
type VirtualMachineScaleSetsExtension struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              VirtualMachineScaleSetsExtension_Spec   `json:"spec,omitempty"`
	Status            VirtualMachineScaleSetsExtension_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &VirtualMachineScaleSetsExtension{}

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

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

var _ conversion.Convertible = &VirtualMachineScaleSetsExtension{}

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

	return extension.AssignProperties_From_VirtualMachineScaleSetsExtension(source)
}

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

	return extension.AssignProperties_To_VirtualMachineScaleSetsExtension(destination)
}

var _ configmaps.Exporter = &VirtualMachineScaleSetsExtension{}

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

var _ secrets.Exporter = &VirtualMachineScaleSetsExtension{}

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

var _ genruntime.ImportableResource = &VirtualMachineScaleSetsExtension{}

// InitializeSpec initializes the spec for this resource from the given status
func (extension *VirtualMachineScaleSetsExtension) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*VirtualMachineScaleSetsExtension_STATUS); ok {
		return extension.Spec.Initialize_From_VirtualMachineScaleSetsExtension_STATUS(s)
	}

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

var _ genruntime.KubernetesResource = &VirtualMachineScaleSetsExtension{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2022-03-01"
func (extension VirtualMachineScaleSetsExtension) GetAPIVersion() string {
	return "2022-03-01"
}

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.Compute/virtualMachineScaleSets/extensions"
func (extension *VirtualMachineScaleSetsExtension) GetType() string {
	return "Microsoft.Compute/virtualMachineScaleSets/extensions"
}

// NewEmptyStatus returns a new empty (blank) status
func (extension *VirtualMachineScaleSetsExtension) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &VirtualMachineScaleSetsExtension_STATUS{}
}

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

	group, kind := genruntime.LookupOwnerGroupKind(extension.Spec)
	return extension.Spec.Owner.AsResourceReference(group, kind)
}

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

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

	extension.Status = st
	return nil
}

// AssignProperties_From_VirtualMachineScaleSetsExtension populates our VirtualMachineScaleSetsExtension from the provided source VirtualMachineScaleSetsExtension
func (extension *VirtualMachineScaleSetsExtension) AssignProperties_From_VirtualMachineScaleSetsExtension(source *storage.VirtualMachineScaleSetsExtension) error {

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

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

	// Status
	var status VirtualMachineScaleSetsExtension_STATUS
	err = status.AssignProperties_From_VirtualMachineScaleSetsExtension_STATUS(&source.Status)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_From_VirtualMachineScaleSetsExtension_STATUS() to populate field Status")
	}
	extension.Status = status

	// No error
	return nil
}

// AssignProperties_To_VirtualMachineScaleSetsExtension populates the provided destination VirtualMachineScaleSetsExtension from our VirtualMachineScaleSetsExtension
func (extension *VirtualMachineScaleSetsExtension) AssignProperties_To_VirtualMachineScaleSetsExtension(destination *storage.VirtualMachineScaleSetsExtension) error {

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

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

	// Status
	var status storage.VirtualMachineScaleSetsExtension_STATUS
	err = extension.Status.AssignProperties_To_VirtualMachineScaleSetsExtension_STATUS(&status)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_To_VirtualMachineScaleSetsExtension_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 (extension *VirtualMachineScaleSetsExtension) OriginalGVK() *schema.GroupVersionKind {
	return &schema.GroupVersionKind{
		Group:   GroupVersion.Group,
		Version: extension.Spec.OriginalVersion(),
		Kind:    "VirtualMachineScaleSetsExtension",
	}
}

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2022-03-01/virtualMachineScaleSet.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/extensions/{vmssExtensionName}
type VirtualMachineScaleSetsExtensionList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []VirtualMachineScaleSetsExtension `json:"items"`
}

type VirtualMachineScaleSetsExtension_Spec struct {
	// AutoUpgradeMinorVersion: Indicates whether the extension should use a newer minor version if one is available at
	// deployment time. Once deployed, however, the extension will not upgrade minor versions unless redeployed, even with this
	// property set to true.
	AutoUpgradeMinorVersion *bool `json:"autoUpgradeMinorVersion,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"`

	// EnableAutomaticUpgrade: Indicates whether the extension should be automatically upgraded by the platform if there is a
	// newer version of the extension available.
	EnableAutomaticUpgrade *bool `json:"enableAutomaticUpgrade,omitempty"`

	// ForceUpdateTag: If a value is provided and is different from the previous value, the extension handler will be forced to
	// update even if the extension configuration has not changed.
	ForceUpdateTag *string `json:"forceUpdateTag,omitempty"`

	// OperatorSpec: The specification for configuring operator behavior. This field is interpreted by the operator and not
	// passed directly to Azure
	OperatorSpec *VirtualMachineScaleSetsExtensionOperatorSpec `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 compute.azure.com/VirtualMachineScaleSet resource
	Owner *genruntime.KnownResourceReference `group:"compute.azure.com" json:"owner,omitempty" kind:"VirtualMachineScaleSet"`

	// ProtectedSettings: The extension can contain either protectedSettings or protectedSettingsFromKeyVault or no protected
	// settings at all.
	ProtectedSettings *genruntime.SecretMapReference `json:"protectedSettings,omitempty"`

	// ProtectedSettingsFromKeyVault: The extensions protected settings that are passed by reference, and consumed from key
	// vault
	ProtectedSettingsFromKeyVault *KeyVaultSecretReference `json:"protectedSettingsFromKeyVault,omitempty"`

	// ProvisionAfterExtensions: Collection of extension names after which this extension needs to be provisioned.
	ProvisionAfterExtensions []string `json:"provisionAfterExtensions,omitempty"`

	// Publisher: The name of the extension handler publisher.
	Publisher *string `json:"publisher,omitempty"`

	// Settings: Json formatted public settings for the extension.
	Settings map[string]v1.JSON `json:"settings,omitempty"`

	// SuppressFailures: Indicates whether failures stemming from the extension will be suppressed (Operational failures such
	// as not connecting to the VM will not be suppressed regardless of this value). The default is false.
	SuppressFailures *bool `json:"suppressFailures,omitempty"`

	// Type: Specifies the type of the extension; an example is "CustomScriptExtension".
	Type *string `json:"type,omitempty"`

	// TypeHandlerVersion: Specifies the version of the script handler.
	TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"`
}

var _ genruntime.ARMTransformer = &VirtualMachineScaleSetsExtension_Spec{}

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

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

	// Set property "Properties":
	if extension.AutoUpgradeMinorVersion != nil ||
		extension.EnableAutomaticUpgrade != nil ||
		extension.ForceUpdateTag != nil ||
		extension.ProtectedSettings != nil ||
		extension.ProtectedSettingsFromKeyVault != nil ||
		extension.ProvisionAfterExtensions != nil ||
		extension.Publisher != nil ||
		extension.Settings != nil ||
		extension.SuppressFailures != nil ||
		extension.Type != nil ||
		extension.TypeHandlerVersion != nil {
		result.Properties = &arm.VirtualMachineScaleSetExtensionProperties{}
	}
	if extension.AutoUpgradeMinorVersion != nil {
		autoUpgradeMinorVersion := *extension.AutoUpgradeMinorVersion
		result.Properties.AutoUpgradeMinorVersion = &autoUpgradeMinorVersion
	}
	if extension.EnableAutomaticUpgrade != nil {
		enableAutomaticUpgrade := *extension.EnableAutomaticUpgrade
		result.Properties.EnableAutomaticUpgrade = &enableAutomaticUpgrade
	}
	if extension.ForceUpdateTag != nil {
		forceUpdateTag := *extension.ForceUpdateTag
		result.Properties.ForceUpdateTag = &forceUpdateTag
	}
	if extension.ProtectedSettings != nil {
		var temp map[string]string
		tempSecret, err := resolved.ResolvedSecretMaps.Lookup(*extension.ProtectedSettings)
		if err != nil {
			return nil, eris.Wrap(err, "looking up secret for property temp")
		}
		temp = tempSecret
		result.Properties.ProtectedSettings = temp
	}
	if extension.ProtectedSettingsFromKeyVault != nil {
		protectedSettingsFromKeyVault_ARM, err := extension.ProtectedSettingsFromKeyVault.ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		protectedSettingsFromKeyVault := *protectedSettingsFromKeyVault_ARM.(*arm.KeyVaultSecretReference)
		result.Properties.ProtectedSettingsFromKeyVault = &protectedSettingsFromKeyVault
	}
	for _, item := range extension.ProvisionAfterExtensions {
		result.Properties.ProvisionAfterExtensions = append(result.Properties.ProvisionAfterExtensions, item)
	}
	if extension.Publisher != nil {
		publisher := *extension.Publisher
		result.Properties.Publisher = &publisher
	}
	if extension.Settings != nil {
		result.Properties.Settings = make(map[string]v1.JSON, len(extension.Settings))
		for key, value := range extension.Settings {
			result.Properties.Settings[key] = *value.DeepCopy()
		}
	}
	if extension.SuppressFailures != nil {
		suppressFailures := *extension.SuppressFailures
		result.Properties.SuppressFailures = &suppressFailures
	}
	if extension.Type != nil {
		typeVar := *extension.Type
		result.Properties.Type = &typeVar
	}
	if extension.TypeHandlerVersion != nil {
		typeHandlerVersion := *extension.TypeHandlerVersion
		result.Properties.TypeHandlerVersion = &typeHandlerVersion
	}
	return result, nil
}

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

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

	// Set property "AutoUpgradeMinorVersion":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AutoUpgradeMinorVersion != nil {
			autoUpgradeMinorVersion := *typedInput.Properties.AutoUpgradeMinorVersion
			extension.AutoUpgradeMinorVersion = &autoUpgradeMinorVersion
		}
	}

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

	// Set property "EnableAutomaticUpgrade":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.EnableAutomaticUpgrade != nil {
			enableAutomaticUpgrade := *typedInput.Properties.EnableAutomaticUpgrade
			extension.EnableAutomaticUpgrade = &enableAutomaticUpgrade
		}
	}

	// Set property "ForceUpdateTag":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ForceUpdateTag != nil {
			forceUpdateTag := *typedInput.Properties.ForceUpdateTag
			extension.ForceUpdateTag = &forceUpdateTag
		}
	}

	// no assignment for property "OperatorSpec"

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

	// no assignment for property "ProtectedSettings"

	// Set property "ProtectedSettingsFromKeyVault":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ProtectedSettingsFromKeyVault != nil {
			var protectedSettingsFromKeyVault1 KeyVaultSecretReference
			err := protectedSettingsFromKeyVault1.PopulateFromARM(owner, *typedInput.Properties.ProtectedSettingsFromKeyVault)
			if err != nil {
				return err
			}
			protectedSettingsFromKeyVault := protectedSettingsFromKeyVault1
			extension.ProtectedSettingsFromKeyVault = &protectedSettingsFromKeyVault
		}
	}

	// Set property "ProvisionAfterExtensions":
	// copying flattened property:
	if typedInput.Properties != nil {
		for _, item := range typedInput.Properties.ProvisionAfterExtensions {
			extension.ProvisionAfterExtensions = append(extension.ProvisionAfterExtensions, item)
		}
	}

	// Set property "Publisher":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Publisher != nil {
			publisher := *typedInput.Properties.Publisher
			extension.Publisher = &publisher
		}
	}

	// Set property "Settings":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Settings != nil {
			extension.Settings = make(map[string]v1.JSON, len(typedInput.Properties.Settings))
			for key, value := range typedInput.Properties.Settings {
				extension.Settings[key] = *value.DeepCopy()
			}
		}
	}

	// Set property "SuppressFailures":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.SuppressFailures != nil {
			suppressFailures := *typedInput.Properties.SuppressFailures
			extension.SuppressFailures = &suppressFailures
		}
	}

	// Set property "Type":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Type != nil {
			typeVar := *typedInput.Properties.Type
			extension.Type = &typeVar
		}
	}

	// Set property "TypeHandlerVersion":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.TypeHandlerVersion != nil {
			typeHandlerVersion := *typedInput.Properties.TypeHandlerVersion
			extension.TypeHandlerVersion = &typeHandlerVersion
		}
	}

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &VirtualMachineScaleSetsExtension_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.VirtualMachineScaleSetsExtension_Spec{}
	err := extension.AssignProperties_To_VirtualMachineScaleSetsExtension_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_VirtualMachineScaleSetsExtension_Spec populates our VirtualMachineScaleSetsExtension_Spec from the provided source VirtualMachineScaleSetsExtension_Spec
func (extension *VirtualMachineScaleSetsExtension_Spec) AssignProperties_From_VirtualMachineScaleSetsExtension_Spec(source *storage.VirtualMachineScaleSetsExtension_Spec) error {

	// AutoUpgradeMinorVersion
	if source.AutoUpgradeMinorVersion != nil {
		autoUpgradeMinorVersion := *source.AutoUpgradeMinorVersion
		extension.AutoUpgradeMinorVersion = &autoUpgradeMinorVersion
	} else {
		extension.AutoUpgradeMinorVersion = nil
	}

	// AzureName
	extension.AzureName = source.AzureName

	// EnableAutomaticUpgrade
	if source.EnableAutomaticUpgrade != nil {
		enableAutomaticUpgrade := *source.EnableAutomaticUpgrade
		extension.EnableAutomaticUpgrade = &enableAutomaticUpgrade
	} else {
		extension.EnableAutomaticUpgrade = nil
	}

	// ForceUpdateTag
	extension.ForceUpdateTag = genruntime.ClonePointerToString(source.ForceUpdateTag)

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

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

	// ProtectedSettings
	if source.ProtectedSettings != nil {
		protectedSetting := source.ProtectedSettings.Copy()
		extension.ProtectedSettings = &protectedSetting
	} else {
		extension.ProtectedSettings = nil
	}

	// ProtectedSettingsFromKeyVault
	if source.ProtectedSettingsFromKeyVault != nil {
		var protectedSettingsFromKeyVault KeyVaultSecretReference
		err := protectedSettingsFromKeyVault.AssignProperties_From_KeyVaultSecretReference(source.ProtectedSettingsFromKeyVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_KeyVaultSecretReference() to populate field ProtectedSettingsFromKeyVault")
		}
		extension.ProtectedSettingsFromKeyVault = &protectedSettingsFromKeyVault
	} else {
		extension.ProtectedSettingsFromKeyVault = nil
	}

	// ProvisionAfterExtensions
	extension.ProvisionAfterExtensions = genruntime.CloneSliceOfString(source.ProvisionAfterExtensions)

	// Publisher
	extension.Publisher = genruntime.ClonePointerToString(source.Publisher)

	// Settings
	if source.Settings != nil {
		settingMap := make(map[string]v1.JSON, len(source.Settings))
		for settingKey, settingValue := range source.Settings {
			settingMap[settingKey] = *settingValue.DeepCopy()
		}
		extension.Settings = settingMap
	} else {
		extension.Settings = nil
	}

	// SuppressFailures
	if source.SuppressFailures != nil {
		suppressFailure := *source.SuppressFailures
		extension.SuppressFailures = &suppressFailure
	} else {
		extension.SuppressFailures = nil
	}

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

	// TypeHandlerVersion
	extension.TypeHandlerVersion = genruntime.ClonePointerToString(source.TypeHandlerVersion)

	// No error
	return nil
}

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

	// AutoUpgradeMinorVersion
	if extension.AutoUpgradeMinorVersion != nil {
		autoUpgradeMinorVersion := *extension.AutoUpgradeMinorVersion
		destination.AutoUpgradeMinorVersion = &autoUpgradeMinorVersion
	} else {
		destination.AutoUpgradeMinorVersion = nil
	}

	// AzureName
	destination.AzureName = extension.AzureName

	// EnableAutomaticUpgrade
	if extension.EnableAutomaticUpgrade != nil {
		enableAutomaticUpgrade := *extension.EnableAutomaticUpgrade
		destination.EnableAutomaticUpgrade = &enableAutomaticUpgrade
	} else {
		destination.EnableAutomaticUpgrade = nil
	}

	// ForceUpdateTag
	destination.ForceUpdateTag = genruntime.ClonePointerToString(extension.ForceUpdateTag)

	// OperatorSpec
	if extension.OperatorSpec != nil {
		var operatorSpec storage.VirtualMachineScaleSetsExtensionOperatorSpec
		err := extension.OperatorSpec.AssignProperties_To_VirtualMachineScaleSetsExtensionOperatorSpec(&operatorSpec)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_VirtualMachineScaleSetsExtensionOperatorSpec() to populate field OperatorSpec")
		}
		destination.OperatorSpec = &operatorSpec
	} else {
		destination.OperatorSpec = nil
	}

	// OriginalVersion
	destination.OriginalVersion = extension.OriginalVersion()

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

	// ProtectedSettings
	if extension.ProtectedSettings != nil {
		protectedSetting := extension.ProtectedSettings.Copy()
		destination.ProtectedSettings = &protectedSetting
	} else {
		destination.ProtectedSettings = nil
	}

	// ProtectedSettingsFromKeyVault
	if extension.ProtectedSettingsFromKeyVault != nil {
		var protectedSettingsFromKeyVault storage.KeyVaultSecretReference
		err := extension.ProtectedSettingsFromKeyVault.AssignProperties_To_KeyVaultSecretReference(&protectedSettingsFromKeyVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_KeyVaultSecretReference() to populate field ProtectedSettingsFromKeyVault")
		}
		destination.ProtectedSettingsFromKeyVault = &protectedSettingsFromKeyVault
	} else {
		destination.ProtectedSettingsFromKeyVault = nil
	}

	// ProvisionAfterExtensions
	destination.ProvisionAfterExtensions = genruntime.CloneSliceOfString(extension.ProvisionAfterExtensions)

	// Publisher
	destination.Publisher = genruntime.ClonePointerToString(extension.Publisher)

	// Settings
	if extension.Settings != nil {
		settingMap := make(map[string]v1.JSON, len(extension.Settings))
		for settingKey, settingValue := range extension.Settings {
			settingMap[settingKey] = *settingValue.DeepCopy()
		}
		destination.Settings = settingMap
	} else {
		destination.Settings = nil
	}

	// SuppressFailures
	if extension.SuppressFailures != nil {
		suppressFailure := *extension.SuppressFailures
		destination.SuppressFailures = &suppressFailure
	} else {
		destination.SuppressFailures = nil
	}

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

	// TypeHandlerVersion
	destination.TypeHandlerVersion = genruntime.ClonePointerToString(extension.TypeHandlerVersion)

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

	// No error
	return nil
}

// Initialize_From_VirtualMachineScaleSetsExtension_STATUS populates our VirtualMachineScaleSetsExtension_Spec from the provided source VirtualMachineScaleSetsExtension_STATUS
func (extension *VirtualMachineScaleSetsExtension_Spec) Initialize_From_VirtualMachineScaleSetsExtension_STATUS(source *VirtualMachineScaleSetsExtension_STATUS) error {

	// AutoUpgradeMinorVersion
	if source.AutoUpgradeMinorVersion != nil {
		autoUpgradeMinorVersion := *source.AutoUpgradeMinorVersion
		extension.AutoUpgradeMinorVersion = &autoUpgradeMinorVersion
	} else {
		extension.AutoUpgradeMinorVersion = nil
	}

	// EnableAutomaticUpgrade
	if source.EnableAutomaticUpgrade != nil {
		enableAutomaticUpgrade := *source.EnableAutomaticUpgrade
		extension.EnableAutomaticUpgrade = &enableAutomaticUpgrade
	} else {
		extension.EnableAutomaticUpgrade = nil
	}

	// ForceUpdateTag
	extension.ForceUpdateTag = genruntime.ClonePointerToString(source.ForceUpdateTag)

	// ProtectedSettingsFromKeyVault
	if source.ProtectedSettingsFromKeyVault != nil {
		var protectedSettingsFromKeyVault KeyVaultSecretReference
		err := protectedSettingsFromKeyVault.Initialize_From_KeyVaultSecretReference_STATUS(source.ProtectedSettingsFromKeyVault)
		if err != nil {
			return eris.Wrap(err, "calling Initialize_From_KeyVaultSecretReference_STATUS() to populate field ProtectedSettingsFromKeyVault")
		}
		extension.ProtectedSettingsFromKeyVault = &protectedSettingsFromKeyVault
	} else {
		extension.ProtectedSettingsFromKeyVault = nil
	}

	// ProvisionAfterExtensions
	extension.ProvisionAfterExtensions = genruntime.CloneSliceOfString(source.ProvisionAfterExtensions)

	// Publisher
	extension.Publisher = genruntime.ClonePointerToString(source.Publisher)

	// Settings
	if source.Settings != nil {
		settingMap := make(map[string]v1.JSON, len(source.Settings))
		for settingKey, settingValue := range source.Settings {
			settingMap[settingKey] = *settingValue.DeepCopy()
		}
		extension.Settings = settingMap
	} else {
		extension.Settings = nil
	}

	// SuppressFailures
	if source.SuppressFailures != nil {
		suppressFailure := *source.SuppressFailures
		extension.SuppressFailures = &suppressFailure
	} else {
		extension.SuppressFailures = nil
	}

	// Type
	extension.Type = genruntime.ClonePointerToString(source.PropertiesType)

	// TypeHandlerVersion
	extension.TypeHandlerVersion = genruntime.ClonePointerToString(source.TypeHandlerVersion)

	// No error
	return nil
}

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

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

type VirtualMachineScaleSetsExtension_STATUS struct {
	// AutoUpgradeMinorVersion: Indicates whether the extension should use a newer minor version if one is available at
	// deployment time. Once deployed, however, the extension will not upgrade minor versions unless redeployed, even with this
	// property set to true.
	AutoUpgradeMinorVersion *bool `json:"autoUpgradeMinorVersion,omitempty"`

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

	// EnableAutomaticUpgrade: Indicates whether the extension should be automatically upgraded by the platform if there is a
	// newer version of the extension available.
	EnableAutomaticUpgrade *bool `json:"enableAutomaticUpgrade,omitempty"`

	// ForceUpdateTag: If a value is provided and is different from the previous value, the extension handler will be forced to
	// update even if the extension configuration has not changed.
	ForceUpdateTag *string `json:"forceUpdateTag,omitempty"`

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

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

	// PropertiesType: Specifies the type of the extension; an example is "CustomScriptExtension".
	PropertiesType *string `json:"properties_type,omitempty"`

	// ProtectedSettingsFromKeyVault: The extensions protected settings that are passed by reference, and consumed from key
	// vault
	ProtectedSettingsFromKeyVault *KeyVaultSecretReference_STATUS `json:"protectedSettingsFromKeyVault,omitempty"`

	// ProvisionAfterExtensions: Collection of extension names after which this extension needs to be provisioned.
	ProvisionAfterExtensions []string `json:"provisionAfterExtensions,omitempty"`

	// ProvisioningState: The provisioning state, which only appears in the response.
	ProvisioningState *string `json:"provisioningState,omitempty"`

	// Publisher: The name of the extension handler publisher.
	Publisher *string `json:"publisher,omitempty"`

	// Settings: Json formatted public settings for the extension.
	Settings map[string]v1.JSON `json:"settings,omitempty"`

	// SuppressFailures: Indicates whether failures stemming from the extension will be suppressed (Operational failures such
	// as not connecting to the VM will not be suppressed regardless of this value). The default is false.
	SuppressFailures *bool `json:"suppressFailures,omitempty"`

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

	// TypeHandlerVersion: Specifies the version of the script handler.
	TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"`
}

var _ genruntime.ConvertibleStatus = &VirtualMachineScaleSetsExtension_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.VirtualMachineScaleSetsExtension_STATUS{}
	err := extension.AssignProperties_To_VirtualMachineScaleSetsExtension_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 = &VirtualMachineScaleSetsExtension_STATUS{}

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

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

	// Set property "AutoUpgradeMinorVersion":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AutoUpgradeMinorVersion != nil {
			autoUpgradeMinorVersion := *typedInput.Properties.AutoUpgradeMinorVersion
			extension.AutoUpgradeMinorVersion = &autoUpgradeMinorVersion
		}
	}

	// no assignment for property "Conditions"

	// Set property "EnableAutomaticUpgrade":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.EnableAutomaticUpgrade != nil {
			enableAutomaticUpgrade := *typedInput.Properties.EnableAutomaticUpgrade
			extension.EnableAutomaticUpgrade = &enableAutomaticUpgrade
		}
	}

	// Set property "ForceUpdateTag":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ForceUpdateTag != nil {
			forceUpdateTag := *typedInput.Properties.ForceUpdateTag
			extension.ForceUpdateTag = &forceUpdateTag
		}
	}

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

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

	// Set property "PropertiesType":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Type != nil {
			propertiesType := *typedInput.Properties.Type
			extension.PropertiesType = &propertiesType
		}
	}

	// Set property "ProtectedSettingsFromKeyVault":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ProtectedSettingsFromKeyVault != nil {
			var protectedSettingsFromKeyVault1 KeyVaultSecretReference_STATUS
			err := protectedSettingsFromKeyVault1.PopulateFromARM(owner, *typedInput.Properties.ProtectedSettingsFromKeyVault)
			if err != nil {
				return err
			}
			protectedSettingsFromKeyVault := protectedSettingsFromKeyVault1
			extension.ProtectedSettingsFromKeyVault = &protectedSettingsFromKeyVault
		}
	}

	// Set property "ProvisionAfterExtensions":
	// copying flattened property:
	if typedInput.Properties != nil {
		for _, item := range typedInput.Properties.ProvisionAfterExtensions {
			extension.ProvisionAfterExtensions = append(extension.ProvisionAfterExtensions, item)
		}
	}

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

	// Set property "Publisher":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Publisher != nil {
			publisher := *typedInput.Properties.Publisher
			extension.Publisher = &publisher
		}
	}

	// Set property "Settings":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Settings != nil {
			extension.Settings = make(map[string]v1.JSON, len(typedInput.Properties.Settings))
			for key, value := range typedInput.Properties.Settings {
				extension.Settings[key] = *value.DeepCopy()
			}
		}
	}

	// Set property "SuppressFailures":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.SuppressFailures != nil {
			suppressFailures := *typedInput.Properties.SuppressFailures
			extension.SuppressFailures = &suppressFailures
		}
	}

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

	// Set property "TypeHandlerVersion":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.TypeHandlerVersion != nil {
			typeHandlerVersion := *typedInput.Properties.TypeHandlerVersion
			extension.TypeHandlerVersion = &typeHandlerVersion
		}
	}

	// No error
	return nil
}

// AssignProperties_From_VirtualMachineScaleSetsExtension_STATUS populates our VirtualMachineScaleSetsExtension_STATUS from the provided source VirtualMachineScaleSetsExtension_STATUS
func (extension *VirtualMachineScaleSetsExtension_STATUS) AssignProperties_From_VirtualMachineScaleSetsExtension_STATUS(source *storage.VirtualMachineScaleSetsExtension_STATUS) error {

	// AutoUpgradeMinorVersion
	if source.AutoUpgradeMinorVersion != nil {
		autoUpgradeMinorVersion := *source.AutoUpgradeMinorVersion
		extension.AutoUpgradeMinorVersion = &autoUpgradeMinorVersion
	} else {
		extension.AutoUpgradeMinorVersion = nil
	}

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

	// EnableAutomaticUpgrade
	if source.EnableAutomaticUpgrade != nil {
		enableAutomaticUpgrade := *source.EnableAutomaticUpgrade
		extension.EnableAutomaticUpgrade = &enableAutomaticUpgrade
	} else {
		extension.EnableAutomaticUpgrade = nil
	}

	// ForceUpdateTag
	extension.ForceUpdateTag = genruntime.ClonePointerToString(source.ForceUpdateTag)

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

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

	// PropertiesType
	extension.PropertiesType = genruntime.ClonePointerToString(source.PropertiesType)

	// ProtectedSettingsFromKeyVault
	if source.ProtectedSettingsFromKeyVault != nil {
		var protectedSettingsFromKeyVault KeyVaultSecretReference_STATUS
		err := protectedSettingsFromKeyVault.AssignProperties_From_KeyVaultSecretReference_STATUS(source.ProtectedSettingsFromKeyVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_KeyVaultSecretReference_STATUS() to populate field ProtectedSettingsFromKeyVault")
		}
		extension.ProtectedSettingsFromKeyVault = &protectedSettingsFromKeyVault
	} else {
		extension.ProtectedSettingsFromKeyVault = nil
	}

	// ProvisionAfterExtensions
	extension.ProvisionAfterExtensions = genruntime.CloneSliceOfString(source.ProvisionAfterExtensions)

	// ProvisioningState
	extension.ProvisioningState = genruntime.ClonePointerToString(source.ProvisioningState)

	// Publisher
	extension.Publisher = genruntime.ClonePointerToString(source.Publisher)

	// Settings
	if source.Settings != nil {
		settingMap := make(map[string]v1.JSON, len(source.Settings))
		for settingKey, settingValue := range source.Settings {
			settingMap[settingKey] = *settingValue.DeepCopy()
		}
		extension.Settings = settingMap
	} else {
		extension.Settings = nil
	}

	// SuppressFailures
	if source.SuppressFailures != nil {
		suppressFailure := *source.SuppressFailures
		extension.SuppressFailures = &suppressFailure
	} else {
		extension.SuppressFailures = nil
	}

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

	// TypeHandlerVersion
	extension.TypeHandlerVersion = genruntime.ClonePointerToString(source.TypeHandlerVersion)

	// No error
	return nil
}

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

	// AutoUpgradeMinorVersion
	if extension.AutoUpgradeMinorVersion != nil {
		autoUpgradeMinorVersion := *extension.AutoUpgradeMinorVersion
		destination.AutoUpgradeMinorVersion = &autoUpgradeMinorVersion
	} else {
		destination.AutoUpgradeMinorVersion = nil
	}

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

	// EnableAutomaticUpgrade
	if extension.EnableAutomaticUpgrade != nil {
		enableAutomaticUpgrade := *extension.EnableAutomaticUpgrade
		destination.EnableAutomaticUpgrade = &enableAutomaticUpgrade
	} else {
		destination.EnableAutomaticUpgrade = nil
	}

	// ForceUpdateTag
	destination.ForceUpdateTag = genruntime.ClonePointerToString(extension.ForceUpdateTag)

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

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

	// PropertiesType
	destination.PropertiesType = genruntime.ClonePointerToString(extension.PropertiesType)

	// ProtectedSettingsFromKeyVault
	if extension.ProtectedSettingsFromKeyVault != nil {
		var protectedSettingsFromKeyVault storage.KeyVaultSecretReference_STATUS
		err := extension.ProtectedSettingsFromKeyVault.AssignProperties_To_KeyVaultSecretReference_STATUS(&protectedSettingsFromKeyVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_KeyVaultSecretReference_STATUS() to populate field ProtectedSettingsFromKeyVault")
		}
		destination.ProtectedSettingsFromKeyVault = &protectedSettingsFromKeyVault
	} else {
		destination.ProtectedSettingsFromKeyVault = nil
	}

	// ProvisionAfterExtensions
	destination.ProvisionAfterExtensions = genruntime.CloneSliceOfString(extension.ProvisionAfterExtensions)

	// ProvisioningState
	destination.ProvisioningState = genruntime.ClonePointerToString(extension.ProvisioningState)

	// Publisher
	destination.Publisher = genruntime.ClonePointerToString(extension.Publisher)

	// Settings
	if extension.Settings != nil {
		settingMap := make(map[string]v1.JSON, len(extension.Settings))
		for settingKey, settingValue := range extension.Settings {
			settingMap[settingKey] = *settingValue.DeepCopy()
		}
		destination.Settings = settingMap
	} else {
		destination.Settings = nil
	}

	// SuppressFailures
	if extension.SuppressFailures != nil {
		suppressFailure := *extension.SuppressFailures
		destination.SuppressFailures = &suppressFailure
	} else {
		destination.SuppressFailures = nil
	}

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

	// TypeHandlerVersion
	destination.TypeHandlerVersion = genruntime.ClonePointerToString(extension.TypeHandlerVersion)

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

	// No error
	return nil
}

// Describes a reference to Key Vault Secret
type KeyVaultSecretReference struct {
	// +kubebuilder:validation:Required
	// SecretUrl: The URL referencing a secret in a Key Vault.
	SecretUrl *string `json:"secretUrl,omitempty"`

	// +kubebuilder:validation:Required
	// SourceVault: The relative URL of the Key Vault containing the secret.
	SourceVault *SubResource `json:"sourceVault,omitempty"`
}

var _ genruntime.ARMTransformer = &KeyVaultSecretReference{}

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

	// Set property "SecretUrl":
	if reference.SecretUrl != nil {
		secretUrl := *reference.SecretUrl
		result.SecretUrl = &secretUrl
	}

	// Set property "SourceVault":
	if reference.SourceVault != nil {
		sourceVault_ARM, err := reference.SourceVault.ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		sourceVault := *sourceVault_ARM.(*arm.SubResource)
		result.SourceVault = &sourceVault
	}
	return result, nil
}

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

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

	// Set property "SecretUrl":
	if typedInput.SecretUrl != nil {
		secretUrl := *typedInput.SecretUrl
		reference.SecretUrl = &secretUrl
	}

	// Set property "SourceVault":
	if typedInput.SourceVault != nil {
		var sourceVault1 SubResource
		err := sourceVault1.PopulateFromARM(owner, *typedInput.SourceVault)
		if err != nil {
			return err
		}
		sourceVault := sourceVault1
		reference.SourceVault = &sourceVault
	}

	// No error
	return nil
}

// AssignProperties_From_KeyVaultSecretReference populates our KeyVaultSecretReference from the provided source KeyVaultSecretReference
func (reference *KeyVaultSecretReference) AssignProperties_From_KeyVaultSecretReference(source *storage.KeyVaultSecretReference) error {

	// SecretUrl
	reference.SecretUrl = genruntime.ClonePointerToString(source.SecretUrl)

	// SourceVault
	if source.SourceVault != nil {
		var sourceVault SubResource
		err := sourceVault.AssignProperties_From_SubResource(source.SourceVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_SubResource() to populate field SourceVault")
		}
		reference.SourceVault = &sourceVault
	} else {
		reference.SourceVault = nil
	}

	// No error
	return nil
}

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

	// SecretUrl
	destination.SecretUrl = genruntime.ClonePointerToString(reference.SecretUrl)

	// SourceVault
	if reference.SourceVault != nil {
		var sourceVault storage.SubResource
		err := reference.SourceVault.AssignProperties_To_SubResource(&sourceVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_SubResource() to populate field SourceVault")
		}
		destination.SourceVault = &sourceVault
	} else {
		destination.SourceVault = nil
	}

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

	// No error
	return nil
}

// Initialize_From_KeyVaultSecretReference_STATUS populates our KeyVaultSecretReference from the provided source KeyVaultSecretReference_STATUS
func (reference *KeyVaultSecretReference) Initialize_From_KeyVaultSecretReference_STATUS(source *KeyVaultSecretReference_STATUS) error {

	// SecretUrl
	reference.SecretUrl = genruntime.ClonePointerToString(source.SecretUrl)

	// SourceVault
	if source.SourceVault != nil {
		var sourceVault SubResource
		err := sourceVault.Initialize_From_SubResource_STATUS(source.SourceVault)
		if err != nil {
			return eris.Wrap(err, "calling Initialize_From_SubResource_STATUS() to populate field SourceVault")
		}
		reference.SourceVault = &sourceVault
	} else {
		reference.SourceVault = nil
	}

	// No error
	return nil
}

// Describes a reference to Key Vault Secret
type KeyVaultSecretReference_STATUS struct {
	// SecretUrl: The URL referencing a secret in a Key Vault.
	SecretUrl *string `json:"secretUrl,omitempty"`

	// SourceVault: The relative URL of the Key Vault containing the secret.
	SourceVault *SubResource_STATUS `json:"sourceVault,omitempty"`
}

var _ genruntime.FromARMConverter = &KeyVaultSecretReference_STATUS{}

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

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

	// Set property "SecretUrl":
	if typedInput.SecretUrl != nil {
		secretUrl := *typedInput.SecretUrl
		reference.SecretUrl = &secretUrl
	}

	// Set property "SourceVault":
	if typedInput.SourceVault != nil {
		var sourceVault1 SubResource_STATUS
		err := sourceVault1.PopulateFromARM(owner, *typedInput.SourceVault)
		if err != nil {
			return err
		}
		sourceVault := sourceVault1
		reference.SourceVault = &sourceVault
	}

	// No error
	return nil
}

// AssignProperties_From_KeyVaultSecretReference_STATUS populates our KeyVaultSecretReference_STATUS from the provided source KeyVaultSecretReference_STATUS
func (reference *KeyVaultSecretReference_STATUS) AssignProperties_From_KeyVaultSecretReference_STATUS(source *storage.KeyVaultSecretReference_STATUS) error {

	// SecretUrl
	reference.SecretUrl = genruntime.ClonePointerToString(source.SecretUrl)

	// SourceVault
	if source.SourceVault != nil {
		var sourceVault SubResource_STATUS
		err := sourceVault.AssignProperties_From_SubResource_STATUS(source.SourceVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_SubResource_STATUS() to populate field SourceVault")
		}
		reference.SourceVault = &sourceVault
	} else {
		reference.SourceVault = nil
	}

	// No error
	return nil
}

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

	// SecretUrl
	destination.SecretUrl = genruntime.ClonePointerToString(reference.SecretUrl)

	// SourceVault
	if reference.SourceVault != nil {
		var sourceVault storage.SubResource_STATUS
		err := reference.SourceVault.AssignProperties_To_SubResource_STATUS(&sourceVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_SubResource_STATUS() to populate field SourceVault")
		}
		destination.SourceVault = &sourceVault
	} else {
		destination.SourceVault = nil
	}

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

	// No error
	return nil
}

// Details for configuring operator behavior. Fields in this struct are interpreted by the operator directly rather than being passed to Azure
type VirtualMachineScaleSetsExtensionOperatorSpec 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_VirtualMachineScaleSetsExtensionOperatorSpec populates our VirtualMachineScaleSetsExtensionOperatorSpec from the provided source VirtualMachineScaleSetsExtensionOperatorSpec
func (operator *VirtualMachineScaleSetsExtensionOperatorSpec) AssignProperties_From_VirtualMachineScaleSetsExtensionOperatorSpec(source *storage.VirtualMachineScaleSetsExtensionOperatorSpec) 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_VirtualMachineScaleSetsExtensionOperatorSpec populates the provided destination VirtualMachineScaleSetsExtensionOperatorSpec from our VirtualMachineScaleSetsExtensionOperatorSpec
func (operator *VirtualMachineScaleSetsExtensionOperatorSpec) AssignProperties_To_VirtualMachineScaleSetsExtensionOperatorSpec(destination *storage.VirtualMachineScaleSetsExtensionOperatorSpec) 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(&VirtualMachineScaleSetsExtension{}, &VirtualMachineScaleSetsExtensionList{})
}
