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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/apimanagement/v1api20230501preview/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/apimanagement/v1api20230501preview/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,apimanagement}
// +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: /apimanagement/resource-manager/Microsoft.ApiManagement/preview/2023-05-01-preview/apimnamedvalues.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues/{namedValueId}
type NamedValue struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              NamedValue_Spec   `json:"spec,omitempty"`
	Status            NamedValue_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &NamedValue{}

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

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

var _ conversion.Convertible = &NamedValue{}

// ConvertFrom populates our NamedValue from the provided hub NamedValue
func (value *NamedValue) ConvertFrom(hub conversion.Hub) error {
	// intermediate variable for conversion
	var source storage.NamedValue

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

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

	return nil
}

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

	return nil
}

var _ configmaps.Exporter = &NamedValue{}

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

var _ secrets.Exporter = &NamedValue{}

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

var _ genruntime.KubernetesResource = &NamedValue{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2023-05-01-preview"
func (value NamedValue) GetAPIVersion() string {
	return "2023-05-01-preview"
}

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.ApiManagement/service/namedValues"
func (value *NamedValue) GetType() string {
	return "Microsoft.ApiManagement/service/namedValues"
}

// NewEmptyStatus returns a new empty (blank) status
func (value *NamedValue) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &NamedValue_STATUS{}
}

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

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

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

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

	value.Status = st
	return nil
}

// AssignProperties_From_NamedValue populates our NamedValue from the provided source NamedValue
func (value *NamedValue) AssignProperties_From_NamedValue(source *storage.NamedValue) error {

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

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

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

	// No error
	return nil
}

// AssignProperties_To_NamedValue populates the provided destination NamedValue from our NamedValue
func (value *NamedValue) AssignProperties_To_NamedValue(destination *storage.NamedValue) error {

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

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

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

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /apimanagement/resource-manager/Microsoft.ApiManagement/preview/2023-05-01-preview/apimnamedvalues.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/namedValues/{namedValueId}
type NamedValueList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []NamedValue `json:"items"`
}

type NamedValue_Spec struct {
	// +kubebuilder:validation:MaxLength=256
	// +kubebuilder:validation:Pattern="^[^*#&+:<>?]+$"
	// AzureName: The name of the resource in Azure. This is often the same as the name of the resource in Kubernetes but it
	// doesn't have to be.
	AzureName string `json:"azureName,omitempty"`

	// +kubebuilder:validation:Required
	// +kubebuilder:validation:MaxLength=256
	// +kubebuilder:validation:MinLength=1
	// +kubebuilder:validation:Pattern="^[A-Za-z0-9-._]+$"
	// DisplayName: Unique name of NamedValue. It may contain only letters, digits, period, dash, and underscore characters.
	DisplayName *string `json:"displayName,omitempty"`

	// KeyVault: KeyVault location details of the namedValue.
	KeyVault *KeyVaultContractCreateProperties `json:"keyVault,omitempty"`

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

	// Secret: Determines whether the value is a secret and should be encrypted or not. Default value is false.
	Secret *bool `json:"secret,omitempty"`

	// +kubebuilder:validation:MaxItems=32
	// Tags: Optional tags that when provided can be used to filter the NamedValue list.
	Tags []string `json:"tags,omitempty"`

	// +kubebuilder:validation:MaxLength=4096
	// Value: Value of the NamedValue. Can contain policy expressions. It may not be empty or consist only of whitespace. This
	// property will not be filled on 'GET' operations! Use '/listSecrets' POST request to get the value.
	Value *string `json:"value,omitempty"`
}

var _ genruntime.ARMTransformer = &NamedValue_Spec{}

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

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

	// Set property "Properties":
	if value.DisplayName != nil ||
		value.KeyVault != nil ||
		value.Secret != nil ||
		value.Tags != nil ||
		value.Value != nil {
		result.Properties = &arm.NamedValueCreateContractProperties{}
	}
	if value.DisplayName != nil {
		displayName := *value.DisplayName
		result.Properties.DisplayName = &displayName
	}
	if value.KeyVault != nil {
		keyVault_ARM, err := value.KeyVault.ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		keyVault := *keyVault_ARM.(*arm.KeyVaultContractCreateProperties)
		result.Properties.KeyVault = &keyVault
	}
	if value.Secret != nil {
		secret := *value.Secret
		result.Properties.Secret = &secret
	}
	for _, item := range value.Tags {
		result.Properties.Tags = append(result.Properties.Tags, item)
	}
	if value.Value != nil {
		value1 := *value.Value
		result.Properties.Value = &value1
	}
	return result, nil
}

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

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

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

	// Set property "DisplayName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.DisplayName != nil {
			displayName := *typedInput.Properties.DisplayName
			value.DisplayName = &displayName
		}
	}

	// Set property "KeyVault":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.KeyVault != nil {
			var keyVault1 KeyVaultContractCreateProperties
			err := keyVault1.PopulateFromARM(owner, *typedInput.Properties.KeyVault)
			if err != nil {
				return err
			}
			keyVault := keyVault1
			value.KeyVault = &keyVault
		}
	}

	// no assignment for property "OperatorSpec"

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

	// Set property "Secret":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Secret != nil {
			secret := *typedInput.Properties.Secret
			value.Secret = &secret
		}
	}

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

	// Set property "Value":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Value != nil {
			value1 := *typedInput.Properties.Value
			value.Value = &value1
		}
	}

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &NamedValue_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.NamedValue_Spec{}
	err := value.AssignProperties_To_NamedValue_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_NamedValue_Spec populates our NamedValue_Spec from the provided source NamedValue_Spec
func (value *NamedValue_Spec) AssignProperties_From_NamedValue_Spec(source *storage.NamedValue_Spec) error {

	// AzureName
	value.AzureName = source.AzureName

	// DisplayName
	value.DisplayName = genruntime.ClonePointerToString(source.DisplayName)

	// KeyVault
	if source.KeyVault != nil {
		var keyVault KeyVaultContractCreateProperties
		err := keyVault.AssignProperties_From_KeyVaultContractCreateProperties(source.KeyVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_KeyVaultContractCreateProperties() to populate field KeyVault")
		}
		value.KeyVault = &keyVault
	} else {
		value.KeyVault = nil
	}

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

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

	// Secret
	if source.Secret != nil {
		secret := *source.Secret
		value.Secret = &secret
	} else {
		value.Secret = nil
	}

	// Tags
	value.Tags = genruntime.CloneSliceOfString(source.Tags)

	// Value
	value.Value = genruntime.ClonePointerToString(source.Value)

	// No error
	return nil
}

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

	// AzureName
	destination.AzureName = value.AzureName

	// DisplayName
	destination.DisplayName = genruntime.ClonePointerToString(value.DisplayName)

	// KeyVault
	if value.KeyVault != nil {
		var keyVault storage.KeyVaultContractCreateProperties
		err := value.KeyVault.AssignProperties_To_KeyVaultContractCreateProperties(&keyVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_KeyVaultContractCreateProperties() to populate field KeyVault")
		}
		destination.KeyVault = &keyVault
	} else {
		destination.KeyVault = nil
	}

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

	// OriginalVersion
	destination.OriginalVersion = value.OriginalVersion()

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

	// Secret
	if value.Secret != nil {
		secret := *value.Secret
		destination.Secret = &secret
	} else {
		destination.Secret = nil
	}

	// Tags
	destination.Tags = genruntime.CloneSliceOfString(value.Tags)

	// Value
	destination.Value = genruntime.ClonePointerToString(value.Value)

	// 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 (value *NamedValue_Spec) OriginalVersion() string {
	return GroupVersion.Version
}

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

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

	// DisplayName: Unique name of NamedValue. It may contain only letters, digits, period, dash, and underscore characters.
	DisplayName *string `json:"displayName,omitempty"`

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

	// KeyVault: KeyVault location details of the namedValue.
	KeyVault *KeyVaultContractProperties_STATUS `json:"keyVault,omitempty"`

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

	// ProvisioningState: The provisioning state
	ProvisioningState *string `json:"provisioningState,omitempty"`

	// Secret: Determines whether the value is a secret and should be encrypted or not. Default value is false.
	Secret *bool `json:"secret,omitempty"`

	// Tags: Optional tags that when provided can be used to filter the NamedValue list.
	Tags []string `json:"tags,omitempty"`

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

	// Value: Value of the NamedValue. Can contain policy expressions. It may not be empty or consist only of whitespace. This
	// property will not be filled on 'GET' operations! Use '/listSecrets' POST request to get the value.
	Value *string `json:"value,omitempty"`
}

var _ genruntime.ConvertibleStatus = &NamedValue_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.NamedValue_STATUS{}
	err := value.AssignProperties_To_NamedValue_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 = &NamedValue_STATUS{}

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

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

	// no assignment for property "Conditions"

	// Set property "DisplayName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.DisplayName != nil {
			displayName := *typedInput.Properties.DisplayName
			value.DisplayName = &displayName
		}
	}

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

	// Set property "KeyVault":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.KeyVault != nil {
			var keyVault1 KeyVaultContractProperties_STATUS
			err := keyVault1.PopulateFromARM(owner, *typedInput.Properties.KeyVault)
			if err != nil {
				return err
			}
			keyVault := keyVault1
			value.KeyVault = &keyVault
		}
	}

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

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

	// Set property "Secret":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Secret != nil {
			secret := *typedInput.Properties.Secret
			value.Secret = &secret
		}
	}

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

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

	// Set property "Value":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Value != nil {
			value1 := *typedInput.Properties.Value
			value.Value = &value1
		}
	}

	// No error
	return nil
}

// AssignProperties_From_NamedValue_STATUS populates our NamedValue_STATUS from the provided source NamedValue_STATUS
func (value *NamedValue_STATUS) AssignProperties_From_NamedValue_STATUS(source *storage.NamedValue_STATUS) error {

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

	// DisplayName
	value.DisplayName = genruntime.ClonePointerToString(source.DisplayName)

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

	// KeyVault
	if source.KeyVault != nil {
		var keyVault KeyVaultContractProperties_STATUS
		err := keyVault.AssignProperties_From_KeyVaultContractProperties_STATUS(source.KeyVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_KeyVaultContractProperties_STATUS() to populate field KeyVault")
		}
		value.KeyVault = &keyVault
	} else {
		value.KeyVault = nil
	}

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

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

	// Secret
	if source.Secret != nil {
		secret := *source.Secret
		value.Secret = &secret
	} else {
		value.Secret = nil
	}

	// Tags
	value.Tags = genruntime.CloneSliceOfString(source.Tags)

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

	// Value
	value.Value = genruntime.ClonePointerToString(source.Value)

	// No error
	return nil
}

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

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

	// DisplayName
	destination.DisplayName = genruntime.ClonePointerToString(value.DisplayName)

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

	// KeyVault
	if value.KeyVault != nil {
		var keyVault storage.KeyVaultContractProperties_STATUS
		err := value.KeyVault.AssignProperties_To_KeyVaultContractProperties_STATUS(&keyVault)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_KeyVaultContractProperties_STATUS() to populate field KeyVault")
		}
		destination.KeyVault = &keyVault
	} else {
		destination.KeyVault = nil
	}

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

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

	// Secret
	if value.Secret != nil {
		secret := *value.Secret
		destination.Secret = &secret
	} else {
		destination.Secret = nil
	}

	// Tags
	destination.Tags = genruntime.CloneSliceOfString(value.Tags)

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

	// Value
	destination.Value = genruntime.ClonePointerToString(value.Value)

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

	// No error
	return nil
}

// Create keyVault contract details.
type KeyVaultContractCreateProperties struct {
	// IdentityClientId: Null for SystemAssignedIdentity or Client Id for UserAssignedIdentity , which will be used to access
	// key vault secret.
	IdentityClientId *string `json:"identityClientId,omitempty" optionalConfigMapPair:"IdentityClientId"`

	// IdentityClientIdFromConfig: Null for SystemAssignedIdentity or Client Id for UserAssignedIdentity , which will be used
	// to access key vault secret.
	IdentityClientIdFromConfig *genruntime.ConfigMapReference `json:"identityClientIdFromConfig,omitempty" optionalConfigMapPair:"IdentityClientId"`

	// SecretIdentifier: Key vault secret identifier for fetching secret. Providing a versioned secret will prevent
	// auto-refresh. This requires API Management service to be configured with aka.ms/apimmsi
	SecretIdentifier *string `json:"secretIdentifier,omitempty"`
}

var _ genruntime.ARMTransformer = &KeyVaultContractCreateProperties{}

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

	// Set property "IdentityClientId":
	if properties.IdentityClientId != nil {
		identityClientId := *properties.IdentityClientId
		result.IdentityClientId = &identityClientId
	}
	if properties.IdentityClientIdFromConfig != nil {
		identityClientIdValue, err := resolved.ResolvedConfigMaps.Lookup(*properties.IdentityClientIdFromConfig)
		if err != nil {
			return nil, eris.Wrap(err, "looking up configmap for property IdentityClientId")
		}
		identityClientId := identityClientIdValue
		result.IdentityClientId = &identityClientId
	}

	// Set property "SecretIdentifier":
	if properties.SecretIdentifier != nil {
		secretIdentifier := *properties.SecretIdentifier
		result.SecretIdentifier = &secretIdentifier
	}
	return result, nil
}

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

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

	// Set property "IdentityClientId":
	if typedInput.IdentityClientId != nil {
		identityClientId := *typedInput.IdentityClientId
		properties.IdentityClientId = &identityClientId
	}

	// no assignment for property "IdentityClientIdFromConfig"

	// Set property "SecretIdentifier":
	if typedInput.SecretIdentifier != nil {
		secretIdentifier := *typedInput.SecretIdentifier
		properties.SecretIdentifier = &secretIdentifier
	}

	// No error
	return nil
}

// AssignProperties_From_KeyVaultContractCreateProperties populates our KeyVaultContractCreateProperties from the provided source KeyVaultContractCreateProperties
func (properties *KeyVaultContractCreateProperties) AssignProperties_From_KeyVaultContractCreateProperties(source *storage.KeyVaultContractCreateProperties) error {

	// IdentityClientId
	properties.IdentityClientId = genruntime.ClonePointerToString(source.IdentityClientId)

	// IdentityClientIdFromConfig
	if source.IdentityClientIdFromConfig != nil {
		identityClientIdFromConfig := source.IdentityClientIdFromConfig.Copy()
		properties.IdentityClientIdFromConfig = &identityClientIdFromConfig
	} else {
		properties.IdentityClientIdFromConfig = nil
	}

	// SecretIdentifier
	properties.SecretIdentifier = genruntime.ClonePointerToString(source.SecretIdentifier)

	// No error
	return nil
}

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

	// IdentityClientId
	destination.IdentityClientId = genruntime.ClonePointerToString(properties.IdentityClientId)

	// IdentityClientIdFromConfig
	if properties.IdentityClientIdFromConfig != nil {
		identityClientIdFromConfig := properties.IdentityClientIdFromConfig.Copy()
		destination.IdentityClientIdFromConfig = &identityClientIdFromConfig
	} else {
		destination.IdentityClientIdFromConfig = nil
	}

	// SecretIdentifier
	destination.SecretIdentifier = genruntime.ClonePointerToString(properties.SecretIdentifier)

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

	// No error
	return nil
}

// KeyVault contract details.
type KeyVaultContractProperties_STATUS struct {
	// IdentityClientId: Null for SystemAssignedIdentity or Client Id for UserAssignedIdentity , which will be used to access
	// key vault secret.
	IdentityClientId *string `json:"identityClientId,omitempty"`

	// LastStatus: Last time sync and refresh status of secret from key vault.
	LastStatus *KeyVaultLastAccessStatusContractProperties_STATUS `json:"lastStatus,omitempty"`

	// SecretIdentifier: Key vault secret identifier for fetching secret. Providing a versioned secret will prevent
	// auto-refresh. This requires API Management service to be configured with aka.ms/apimmsi
	SecretIdentifier *string `json:"secretIdentifier,omitempty"`
}

var _ genruntime.FromARMConverter = &KeyVaultContractProperties_STATUS{}

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

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

	// Set property "IdentityClientId":
	if typedInput.IdentityClientId != nil {
		identityClientId := *typedInput.IdentityClientId
		properties.IdentityClientId = &identityClientId
	}

	// Set property "LastStatus":
	if typedInput.LastStatus != nil {
		var lastStatus1 KeyVaultLastAccessStatusContractProperties_STATUS
		err := lastStatus1.PopulateFromARM(owner, *typedInput.LastStatus)
		if err != nil {
			return err
		}
		lastStatus := lastStatus1
		properties.LastStatus = &lastStatus
	}

	// Set property "SecretIdentifier":
	if typedInput.SecretIdentifier != nil {
		secretIdentifier := *typedInput.SecretIdentifier
		properties.SecretIdentifier = &secretIdentifier
	}

	// No error
	return nil
}

// AssignProperties_From_KeyVaultContractProperties_STATUS populates our KeyVaultContractProperties_STATUS from the provided source KeyVaultContractProperties_STATUS
func (properties *KeyVaultContractProperties_STATUS) AssignProperties_From_KeyVaultContractProperties_STATUS(source *storage.KeyVaultContractProperties_STATUS) error {

	// IdentityClientId
	properties.IdentityClientId = genruntime.ClonePointerToString(source.IdentityClientId)

	// LastStatus
	if source.LastStatus != nil {
		var lastStatus KeyVaultLastAccessStatusContractProperties_STATUS
		err := lastStatus.AssignProperties_From_KeyVaultLastAccessStatusContractProperties_STATUS(source.LastStatus)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_KeyVaultLastAccessStatusContractProperties_STATUS() to populate field LastStatus")
		}
		properties.LastStatus = &lastStatus
	} else {
		properties.LastStatus = nil
	}

	// SecretIdentifier
	properties.SecretIdentifier = genruntime.ClonePointerToString(source.SecretIdentifier)

	// No error
	return nil
}

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

	// IdentityClientId
	destination.IdentityClientId = genruntime.ClonePointerToString(properties.IdentityClientId)

	// LastStatus
	if properties.LastStatus != nil {
		var lastStatus storage.KeyVaultLastAccessStatusContractProperties_STATUS
		err := properties.LastStatus.AssignProperties_To_KeyVaultLastAccessStatusContractProperties_STATUS(&lastStatus)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_KeyVaultLastAccessStatusContractProperties_STATUS() to populate field LastStatus")
		}
		destination.LastStatus = &lastStatus
	} else {
		destination.LastStatus = nil
	}

	// SecretIdentifier
	destination.SecretIdentifier = genruntime.ClonePointerToString(properties.SecretIdentifier)

	// 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 NamedValueOperatorSpec 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_NamedValueOperatorSpec populates our NamedValueOperatorSpec from the provided source NamedValueOperatorSpec
func (operator *NamedValueOperatorSpec) AssignProperties_From_NamedValueOperatorSpec(source *storage.NamedValueOperatorSpec) 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_NamedValueOperatorSpec populates the provided destination NamedValueOperatorSpec from our NamedValueOperatorSpec
func (operator *NamedValueOperatorSpec) AssignProperties_To_NamedValueOperatorSpec(destination *storage.NamedValueOperatorSpec) 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
}

// Issue contract Update Properties.
type KeyVaultLastAccessStatusContractProperties_STATUS struct {
	// Code: Last status code for sync and refresh of secret from key vault.
	Code *string `json:"code,omitempty"`

	// Message: Details of the error else empty.
	Message *string `json:"message,omitempty"`

	// TimeStampUtc: Last time secret was accessed. The date conforms to the following format: `yyyy-MM-ddTHH:mm:ssZ` as
	// specified by the ISO 8601 standard.
	TimeStampUtc *string `json:"timeStampUtc,omitempty"`
}

var _ genruntime.FromARMConverter = &KeyVaultLastAccessStatusContractProperties_STATUS{}

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

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

	// Set property "Code":
	if typedInput.Code != nil {
		code := *typedInput.Code
		properties.Code = &code
	}

	// Set property "Message":
	if typedInput.Message != nil {
		message := *typedInput.Message
		properties.Message = &message
	}

	// Set property "TimeStampUtc":
	if typedInput.TimeStampUtc != nil {
		timeStampUtc := *typedInput.TimeStampUtc
		properties.TimeStampUtc = &timeStampUtc
	}

	// No error
	return nil
}

// AssignProperties_From_KeyVaultLastAccessStatusContractProperties_STATUS populates our KeyVaultLastAccessStatusContractProperties_STATUS from the provided source KeyVaultLastAccessStatusContractProperties_STATUS
func (properties *KeyVaultLastAccessStatusContractProperties_STATUS) AssignProperties_From_KeyVaultLastAccessStatusContractProperties_STATUS(source *storage.KeyVaultLastAccessStatusContractProperties_STATUS) error {

	// Code
	properties.Code = genruntime.ClonePointerToString(source.Code)

	// Message
	properties.Message = genruntime.ClonePointerToString(source.Message)

	// TimeStampUtc
	properties.TimeStampUtc = genruntime.ClonePointerToString(source.TimeStampUtc)

	// No error
	return nil
}

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

	// Code
	destination.Code = genruntime.ClonePointerToString(properties.Code)

	// Message
	destination.Message = genruntime.ClonePointerToString(properties.Message)

	// TimeStampUtc
	destination.TimeStampUtc = genruntime.ClonePointerToString(properties.TimeStampUtc)

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

	// No error
	return nil
}

func init() {
	SchemeBuilder.Register(&NamedValue{}, &NamedValueList{})
}
