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

import (
	"fmt"
	storage "github.com/Azure/azure-service-operator/v2/api/machinelearningservices/v1api20240401/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,machinelearningservices}
// +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"
// Storage version of v1api20210701.WorkspacesConnection
// Generator information:
// - Generated from: /machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable/2021-07-01/machineLearningServices.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/connections/{connectionName}
type WorkspacesConnection struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              WorkspacesConnection_Spec   `json:"spec,omitempty"`
	Status            WorkspacesConnection_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &WorkspacesConnection{}

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

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

var _ conversion.Convertible = &WorkspacesConnection{}

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

	return connection.AssignProperties_From_WorkspacesConnection(source)
}

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

	return connection.AssignProperties_To_WorkspacesConnection(destination)
}

var _ configmaps.Exporter = &WorkspacesConnection{}

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

var _ secrets.Exporter = &WorkspacesConnection{}

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

var _ genruntime.KubernetesResource = &WorkspacesConnection{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2021-07-01"
func (connection WorkspacesConnection) GetAPIVersion() string {
	return "2021-07-01"
}

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.MachineLearningServices/workspaces/connections"
func (connection *WorkspacesConnection) GetType() string {
	return "Microsoft.MachineLearningServices/workspaces/connections"
}

// NewEmptyStatus returns a new empty (blank) status
func (connection *WorkspacesConnection) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &WorkspacesConnection_STATUS{}
}

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

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

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

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

	connection.Status = st
	return nil
}

// AssignProperties_From_WorkspacesConnection populates our WorkspacesConnection from the provided source WorkspacesConnection
func (connection *WorkspacesConnection) AssignProperties_From_WorkspacesConnection(source *storage.WorkspacesConnection) error {

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

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

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

	// Invoke the augmentConversionForWorkspacesConnection interface (if implemented) to customize the conversion
	var connectionAsAny any = connection
	if augmentedConnection, ok := connectionAsAny.(augmentConversionForWorkspacesConnection); ok {
		err := augmentedConnection.AssignPropertiesFrom(source)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesFrom() for conversion")
		}
	}

	// No error
	return nil
}

// AssignProperties_To_WorkspacesConnection populates the provided destination WorkspacesConnection from our WorkspacesConnection
func (connection *WorkspacesConnection) AssignProperties_To_WorkspacesConnection(destination *storage.WorkspacesConnection) error {

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

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

	// Status
	var status storage.WorkspacesConnection_STATUS
	err = connection.Status.AssignProperties_To_WorkspacesConnection_STATUS(&status)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_To_WorkspacesConnection_STATUS() to populate field Status")
	}
	destination.Status = status

	// Invoke the augmentConversionForWorkspacesConnection interface (if implemented) to customize the conversion
	var connectionAsAny any = connection
	if augmentedConnection, ok := connectionAsAny.(augmentConversionForWorkspacesConnection); ok {
		err := augmentedConnection.AssignPropertiesTo(destination)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesTo() for conversion")
		}
	}

	// No error
	return nil
}

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

// +kubebuilder:object:root=true
// Storage version of v1api20210701.WorkspacesConnection
// Generator information:
// - Generated from: /machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable/2021-07-01/machineLearningServices.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/connections/{connectionName}
type WorkspacesConnectionList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []WorkspacesConnection `json:"items"`
}

type augmentConversionForWorkspacesConnection interface {
	AssignPropertiesFrom(src *storage.WorkspacesConnection) error
	AssignPropertiesTo(dst *storage.WorkspacesConnection) error
}

// Storage version of v1api20210701.WorkspacesConnection_Spec
type WorkspacesConnection_Spec struct {
	AuthType *string `json:"authType,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"`
	Category        *string                           `json:"category,omitempty"`
	OperatorSpec    *WorkspacesConnectionOperatorSpec `json:"operatorSpec,omitempty"`
	OriginalVersion string                            `json:"originalVersion,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 machinelearningservices.azure.com/Workspace resource
	Owner       *genruntime.KnownResourceReference `group:"machinelearningservices.azure.com" json:"owner,omitempty" kind:"Workspace"`
	PropertyBag genruntime.PropertyBag             `json:"$propertyBag,omitempty"`
	Target      *string                            `json:"target,omitempty"`
	Value       *string                            `json:"value,omitempty"`
	ValueFormat *string                            `json:"valueFormat,omitempty"`
}

var _ genruntime.ConvertibleSpec = &WorkspacesConnection_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.WorkspacesConnection_Spec{}
	err := connection.AssignProperties_To_WorkspacesConnection_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_WorkspacesConnection_Spec populates our WorkspacesConnection_Spec from the provided source WorkspacesConnection_Spec
func (connection *WorkspacesConnection_Spec) AssignProperties_From_WorkspacesConnection_Spec(source *storage.WorkspacesConnection_Spec) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(source.PropertyBag)

	// AuthType
	if propertyBag.Contains("AuthType") {
		var authType string
		err := propertyBag.Pull("AuthType", &authType)
		if err != nil {
			return eris.Wrap(err, "pulling 'AuthType' from propertyBag")
		}

		connection.AuthType = &authType
	} else {
		connection.AuthType = nil
	}

	// AzureName
	connection.AzureName = source.AzureName

	// Category
	if propertyBag.Contains("Category") {
		var category string
		err := propertyBag.Pull("Category", &category)
		if err != nil {
			return eris.Wrap(err, "pulling 'Category' from propertyBag")
		}

		connection.Category = &category
	} else {
		connection.Category = nil
	}

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

	// OriginalVersion
	connection.OriginalVersion = source.OriginalVersion

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

	// Properties
	if source.Properties != nil {
		propertyBag.Add("Properties", *source.Properties)
	} else {
		propertyBag.Remove("Properties")
	}

	// Target
	if propertyBag.Contains("Target") {
		var target string
		err := propertyBag.Pull("Target", &target)
		if err != nil {
			return eris.Wrap(err, "pulling 'Target' from propertyBag")
		}

		connection.Target = &target
	} else {
		connection.Target = nil
	}

	// Value
	if propertyBag.Contains("Value") {
		var value string
		err := propertyBag.Pull("Value", &value)
		if err != nil {
			return eris.Wrap(err, "pulling 'Value' from propertyBag")
		}

		connection.Value = &value
	} else {
		connection.Value = nil
	}

	// ValueFormat
	if propertyBag.Contains("ValueFormat") {
		var valueFormat string
		err := propertyBag.Pull("ValueFormat", &valueFormat)
		if err != nil {
			return eris.Wrap(err, "pulling 'ValueFormat' from propertyBag")
		}

		connection.ValueFormat = &valueFormat
	} else {
		connection.ValueFormat = nil
	}

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

	// Invoke the augmentConversionForWorkspacesConnection_Spec interface (if implemented) to customize the conversion
	var connectionAsAny any = connection
	if augmentedConnection, ok := connectionAsAny.(augmentConversionForWorkspacesConnection_Spec); ok {
		err := augmentedConnection.AssignPropertiesFrom(source)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesFrom() for conversion")
		}
	}

	// No error
	return nil
}

// AssignProperties_To_WorkspacesConnection_Spec populates the provided destination WorkspacesConnection_Spec from our WorkspacesConnection_Spec
func (connection *WorkspacesConnection_Spec) AssignProperties_To_WorkspacesConnection_Spec(destination *storage.WorkspacesConnection_Spec) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(connection.PropertyBag)

	// AuthType
	if connection.AuthType != nil {
		propertyBag.Add("AuthType", *connection.AuthType)
	} else {
		propertyBag.Remove("AuthType")
	}

	// AzureName
	destination.AzureName = connection.AzureName

	// Category
	if connection.Category != nil {
		propertyBag.Add("Category", *connection.Category)
	} else {
		propertyBag.Remove("Category")
	}

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

	// OriginalVersion
	destination.OriginalVersion = connection.OriginalVersion

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

	// Properties
	if propertyBag.Contains("Properties") {
		var property storage.WorkspaceConnectionPropertiesV2
		err := propertyBag.Pull("Properties", &property)
		if err != nil {
			return eris.Wrap(err, "pulling 'Properties' from propertyBag")
		}

		destination.Properties = &property
	} else {
		destination.Properties = nil
	}

	// Target
	if connection.Target != nil {
		propertyBag.Add("Target", *connection.Target)
	} else {
		propertyBag.Remove("Target")
	}

	// Value
	if connection.Value != nil {
		propertyBag.Add("Value", *connection.Value)
	} else {
		propertyBag.Remove("Value")
	}

	// ValueFormat
	if connection.ValueFormat != nil {
		propertyBag.Add("ValueFormat", *connection.ValueFormat)
	} else {
		propertyBag.Remove("ValueFormat")
	}

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

	// Invoke the augmentConversionForWorkspacesConnection_Spec interface (if implemented) to customize the conversion
	var connectionAsAny any = connection
	if augmentedConnection, ok := connectionAsAny.(augmentConversionForWorkspacesConnection_Spec); ok {
		err := augmentedConnection.AssignPropertiesTo(destination)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesTo() for conversion")
		}
	}

	// No error
	return nil
}

// Storage version of v1api20210701.WorkspacesConnection_STATUS
type WorkspacesConnection_STATUS struct {
	AuthType    *string                `json:"authType,omitempty"`
	Category    *string                `json:"category,omitempty"`
	Conditions  []conditions.Condition `json:"conditions,omitempty"`
	Id          *string                `json:"id,omitempty"`
	Name        *string                `json:"name,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Target      *string                `json:"target,omitempty"`
	Type        *string                `json:"type,omitempty"`
	Value       *string                `json:"value,omitempty"`
	ValueFormat *string                `json:"valueFormat,omitempty"`
}

var _ genruntime.ConvertibleStatus = &WorkspacesConnection_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.WorkspacesConnection_STATUS{}
	err := connection.AssignProperties_To_WorkspacesConnection_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
}

// AssignProperties_From_WorkspacesConnection_STATUS populates our WorkspacesConnection_STATUS from the provided source WorkspacesConnection_STATUS
func (connection *WorkspacesConnection_STATUS) AssignProperties_From_WorkspacesConnection_STATUS(source *storage.WorkspacesConnection_STATUS) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(source.PropertyBag)

	// AuthType
	if propertyBag.Contains("AuthType") {
		var authType string
		err := propertyBag.Pull("AuthType", &authType)
		if err != nil {
			return eris.Wrap(err, "pulling 'AuthType' from propertyBag")
		}

		connection.AuthType = &authType
	} else {
		connection.AuthType = nil
	}

	// Category
	if propertyBag.Contains("Category") {
		var category string
		err := propertyBag.Pull("Category", &category)
		if err != nil {
			return eris.Wrap(err, "pulling 'Category' from propertyBag")
		}

		connection.Category = &category
	} else {
		connection.Category = nil
	}

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

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

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

	// Properties
	if source.Properties != nil {
		propertyBag.Add("Properties", *source.Properties)
	} else {
		propertyBag.Remove("Properties")
	}

	// SystemData
	if source.SystemData != nil {
		propertyBag.Add("SystemData", *source.SystemData)
	} else {
		propertyBag.Remove("SystemData")
	}

	// Target
	if propertyBag.Contains("Target") {
		var target string
		err := propertyBag.Pull("Target", &target)
		if err != nil {
			return eris.Wrap(err, "pulling 'Target' from propertyBag")
		}

		connection.Target = &target
	} else {
		connection.Target = nil
	}

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

	// Value
	if propertyBag.Contains("Value") {
		var value string
		err := propertyBag.Pull("Value", &value)
		if err != nil {
			return eris.Wrap(err, "pulling 'Value' from propertyBag")
		}

		connection.Value = &value
	} else {
		connection.Value = nil
	}

	// ValueFormat
	if propertyBag.Contains("ValueFormat") {
		var valueFormat string
		err := propertyBag.Pull("ValueFormat", &valueFormat)
		if err != nil {
			return eris.Wrap(err, "pulling 'ValueFormat' from propertyBag")
		}

		connection.ValueFormat = &valueFormat
	} else {
		connection.ValueFormat = nil
	}

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

	// Invoke the augmentConversionForWorkspacesConnection_STATUS interface (if implemented) to customize the conversion
	var connectionAsAny any = connection
	if augmentedConnection, ok := connectionAsAny.(augmentConversionForWorkspacesConnection_STATUS); ok {
		err := augmentedConnection.AssignPropertiesFrom(source)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesFrom() for conversion")
		}
	}

	// No error
	return nil
}

// AssignProperties_To_WorkspacesConnection_STATUS populates the provided destination WorkspacesConnection_STATUS from our WorkspacesConnection_STATUS
func (connection *WorkspacesConnection_STATUS) AssignProperties_To_WorkspacesConnection_STATUS(destination *storage.WorkspacesConnection_STATUS) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(connection.PropertyBag)

	// AuthType
	if connection.AuthType != nil {
		propertyBag.Add("AuthType", *connection.AuthType)
	} else {
		propertyBag.Remove("AuthType")
	}

	// Category
	if connection.Category != nil {
		propertyBag.Add("Category", *connection.Category)
	} else {
		propertyBag.Remove("Category")
	}

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

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

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

	// Properties
	if propertyBag.Contains("Properties") {
		var property storage.WorkspaceConnectionPropertiesV2_STATUS
		err := propertyBag.Pull("Properties", &property)
		if err != nil {
			return eris.Wrap(err, "pulling 'Properties' from propertyBag")
		}

		destination.Properties = &property
	} else {
		destination.Properties = nil
	}

	// SystemData
	if propertyBag.Contains("SystemData") {
		var systemDatum storage.SystemData_STATUS
		err := propertyBag.Pull("SystemData", &systemDatum)
		if err != nil {
			return eris.Wrap(err, "pulling 'SystemData' from propertyBag")
		}

		destination.SystemData = &systemDatum
	} else {
		destination.SystemData = nil
	}

	// Target
	if connection.Target != nil {
		propertyBag.Add("Target", *connection.Target)
	} else {
		propertyBag.Remove("Target")
	}

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

	// Value
	if connection.Value != nil {
		propertyBag.Add("Value", *connection.Value)
	} else {
		propertyBag.Remove("Value")
	}

	// ValueFormat
	if connection.ValueFormat != nil {
		propertyBag.Add("ValueFormat", *connection.ValueFormat)
	} else {
		propertyBag.Remove("ValueFormat")
	}

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

	// Invoke the augmentConversionForWorkspacesConnection_STATUS interface (if implemented) to customize the conversion
	var connectionAsAny any = connection
	if augmentedConnection, ok := connectionAsAny.(augmentConversionForWorkspacesConnection_STATUS); ok {
		err := augmentedConnection.AssignPropertiesTo(destination)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesTo() for conversion")
		}
	}

	// No error
	return nil
}

type augmentConversionForWorkspacesConnection_Spec interface {
	AssignPropertiesFrom(src *storage.WorkspacesConnection_Spec) error
	AssignPropertiesTo(dst *storage.WorkspacesConnection_Spec) error
}

type augmentConversionForWorkspacesConnection_STATUS interface {
	AssignPropertiesFrom(src *storage.WorkspacesConnection_STATUS) error
	AssignPropertiesTo(dst *storage.WorkspacesConnection_STATUS) error
}

// Storage version of v1api20210701.WorkspacesConnectionOperatorSpec
// Details for configuring operator behavior. Fields in this struct are interpreted by the operator directly rather than being passed to Azure
type WorkspacesConnectionOperatorSpec struct {
	ConfigMapExpressions []*core.DestinationExpression `json:"configMapExpressions,omitempty"`
	PropertyBag          genruntime.PropertyBag        `json:"$propertyBag,omitempty"`
	SecretExpressions    []*core.DestinationExpression `json:"secretExpressions,omitempty"`
}

// AssignProperties_From_WorkspacesConnectionOperatorSpec populates our WorkspacesConnectionOperatorSpec from the provided source WorkspacesConnectionOperatorSpec
func (operator *WorkspacesConnectionOperatorSpec) AssignProperties_From_WorkspacesConnectionOperatorSpec(source *storage.WorkspacesConnectionOperatorSpec) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(source.PropertyBag)

	// 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
	}

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

	// Invoke the augmentConversionForWorkspacesConnectionOperatorSpec interface (if implemented) to customize the conversion
	var operatorAsAny any = operator
	if augmentedOperator, ok := operatorAsAny.(augmentConversionForWorkspacesConnectionOperatorSpec); ok {
		err := augmentedOperator.AssignPropertiesFrom(source)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesFrom() for conversion")
		}
	}

	// No error
	return nil
}

// AssignProperties_To_WorkspacesConnectionOperatorSpec populates the provided destination WorkspacesConnectionOperatorSpec from our WorkspacesConnectionOperatorSpec
func (operator *WorkspacesConnectionOperatorSpec) AssignProperties_To_WorkspacesConnectionOperatorSpec(destination *storage.WorkspacesConnectionOperatorSpec) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(operator.PropertyBag)

	// 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
	}

	// Invoke the augmentConversionForWorkspacesConnectionOperatorSpec interface (if implemented) to customize the conversion
	var operatorAsAny any = operator
	if augmentedOperator, ok := operatorAsAny.(augmentConversionForWorkspacesConnectionOperatorSpec); ok {
		err := augmentedOperator.AssignPropertiesTo(destination)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesTo() for conversion")
		}
	}

	// No error
	return nil
}

type augmentConversionForWorkspacesConnectionOperatorSpec interface {
	AssignPropertiesFrom(src *storage.WorkspacesConnectionOperatorSpec) error
	AssignPropertiesTo(dst *storage.WorkspacesConnectionOperatorSpec) error
}

func init() {
	SchemeBuilder.Register(&WorkspacesConnection{}, &WorkspacesConnectionList{})
}
