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

import (
	storage "github.com/Azure/azure-service-operator/v2/api/apimanagement/v1api20220801/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"
// Storage version of v1api20230501preview.Subscription
// Generator information:
// - Generated from: /apimanagement/resource-manager/Microsoft.ApiManagement/preview/2023-05-01-preview/apimsubscriptions.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/subscriptions/{sid}
type Subscription struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              Subscription_Spec   `json:"spec,omitempty"`
	Status            Subscription_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &Subscription{}

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

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

var _ conversion.Convertible = &Subscription{}

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

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

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

	return nil
}

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

	return nil
}

var _ configmaps.Exporter = &Subscription{}

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

var _ secrets.Exporter = &Subscription{}

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

var _ genruntime.KubernetesResource = &Subscription{}

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

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

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

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

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

// GetSupportedOperations returns the operations supported by the resource
func (subscription *Subscription) 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/subscriptions"
func (subscription *Subscription) GetType() string {
	return "Microsoft.ApiManagement/service/subscriptions"
}

// NewEmptyStatus returns a new empty (blank) status
func (subscription *Subscription) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &Subscription_STATUS{}
}

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

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

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

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

	subscription.Status = st
	return nil
}

// AssignProperties_From_Subscription populates our Subscription from the provided source Subscription
func (subscription *Subscription) AssignProperties_From_Subscription(source *storage.Subscription) error {

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

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

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

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

	// No error
	return nil
}

// AssignProperties_To_Subscription populates the provided destination Subscription from our Subscription
func (subscription *Subscription) AssignProperties_To_Subscription(destination *storage.Subscription) error {

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

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

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

	// Invoke the augmentConversionForSubscription interface (if implemented) to customize the conversion
	var subscriptionAsAny any = subscription
	if augmentedSubscription, ok := subscriptionAsAny.(augmentConversionForSubscription); ok {
		err := augmentedSubscription.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 (subscription *Subscription) OriginalGVK() *schema.GroupVersionKind {
	return &schema.GroupVersionKind{
		Group:   GroupVersion.Group,
		Version: subscription.Spec.OriginalVersion,
		Kind:    "Subscription",
	}
}

// +kubebuilder:object:root=true
// Storage version of v1api20230501preview.Subscription
// Generator information:
// - Generated from: /apimanagement/resource-manager/Microsoft.ApiManagement/preview/2023-05-01-preview/apimsubscriptions.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/subscriptions/{sid}
type SubscriptionList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Subscription `json:"items"`
}

type augmentConversionForSubscription interface {
	AssignPropertiesFrom(src *storage.Subscription) error
	AssignPropertiesTo(dst *storage.Subscription) error
}

// Storage version of v1api20230501preview.Subscription_Spec
type Subscription_Spec struct {
	AllowTracing *bool `json:"allowTracing,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"`
	DisplayName     *string                   `json:"displayName,omitempty"`
	OperatorSpec    *SubscriptionOperatorSpec `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 apimanagement.azure.com/Service resource
	Owner *genruntime.KnownResourceReference `group:"apimanagement.azure.com" json:"owner,omitempty" kind:"Service"`

	// OwnerReference: User (user id path) for whom subscription is being created in form /users/{userId}
	OwnerReference *genruntime.ResourceReference `armReference:"OwnerId" json:"ownerReference,omitempty"`
	PrimaryKey     *genruntime.SecretReference   `json:"primaryKey,omitempty"`
	PropertyBag    genruntime.PropertyBag        `json:"$propertyBag,omitempty"`
	Scope          *string                       `json:"scope,omitempty"`
	SecondaryKey   *genruntime.SecretReference   `json:"secondaryKey,omitempty"`
	State          *string                       `json:"state,omitempty"`
}

var _ genruntime.ConvertibleSpec = &Subscription_Spec{}

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

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

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

	return nil
}

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

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

	// AllowTracing
	if source.AllowTracing != nil {
		allowTracing := *source.AllowTracing
		subscription.AllowTracing = &allowTracing
	} else {
		subscription.AllowTracing = nil
	}

	// AzureName
	subscription.AzureName = source.AzureName

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

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

	// OriginalVersion
	subscription.OriginalVersion = source.OriginalVersion

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

	// OwnerReference
	if source.OwnerReference != nil {
		ownerReference := source.OwnerReference.Copy()
		subscription.OwnerReference = &ownerReference
	} else {
		subscription.OwnerReference = nil
	}

	// PrimaryKey
	if source.PrimaryKey != nil {
		primaryKey := source.PrimaryKey.Copy()
		subscription.PrimaryKey = &primaryKey
	} else {
		subscription.PrimaryKey = nil
	}

	// Scope
	subscription.Scope = genruntime.ClonePointerToString(source.Scope)

	// SecondaryKey
	if source.SecondaryKey != nil {
		secondaryKey := source.SecondaryKey.Copy()
		subscription.SecondaryKey = &secondaryKey
	} else {
		subscription.SecondaryKey = nil
	}

	// State
	subscription.State = genruntime.ClonePointerToString(source.State)

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

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

	// No error
	return nil
}

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

	// AllowTracing
	if subscription.AllowTracing != nil {
		allowTracing := *subscription.AllowTracing
		destination.AllowTracing = &allowTracing
	} else {
		destination.AllowTracing = nil
	}

	// AzureName
	destination.AzureName = subscription.AzureName

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

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

	// OriginalVersion
	destination.OriginalVersion = subscription.OriginalVersion

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

	// OwnerReference
	if subscription.OwnerReference != nil {
		ownerReference := subscription.OwnerReference.Copy()
		destination.OwnerReference = &ownerReference
	} else {
		destination.OwnerReference = nil
	}

	// PrimaryKey
	if subscription.PrimaryKey != nil {
		primaryKey := subscription.PrimaryKey.Copy()
		destination.PrimaryKey = &primaryKey
	} else {
		destination.PrimaryKey = nil
	}

	// Scope
	destination.Scope = genruntime.ClonePointerToString(subscription.Scope)

	// SecondaryKey
	if subscription.SecondaryKey != nil {
		secondaryKey := subscription.SecondaryKey.Copy()
		destination.SecondaryKey = &secondaryKey
	} else {
		destination.SecondaryKey = nil
	}

	// State
	destination.State = genruntime.ClonePointerToString(subscription.State)

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

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

	// No error
	return nil
}

// Storage version of v1api20230501preview.Subscription_STATUS
type Subscription_STATUS struct {
	AllowTracing     *bool                  `json:"allowTracing,omitempty"`
	Conditions       []conditions.Condition `json:"conditions,omitempty"`
	CreatedDate      *string                `json:"createdDate,omitempty"`
	DisplayName      *string                `json:"displayName,omitempty"`
	EndDate          *string                `json:"endDate,omitempty"`
	ExpirationDate   *string                `json:"expirationDate,omitempty"`
	Id               *string                `json:"id,omitempty"`
	Name             *string                `json:"name,omitempty"`
	NotificationDate *string                `json:"notificationDate,omitempty"`
	OwnerId          *string                `json:"ownerId,omitempty"`
	PropertyBag      genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Scope            *string                `json:"scope,omitempty"`
	StartDate        *string                `json:"startDate,omitempty"`
	State            *string                `json:"state,omitempty"`
	StateComment     *string                `json:"stateComment,omitempty"`
	Type             *string                `json:"type,omitempty"`
}

var _ genruntime.ConvertibleStatus = &Subscription_STATUS{}

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

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

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

	return nil
}

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

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

	// AllowTracing
	if source.AllowTracing != nil {
		allowTracing := *source.AllowTracing
		subscription.AllowTracing = &allowTracing
	} else {
		subscription.AllowTracing = nil
	}

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

	// CreatedDate
	subscription.CreatedDate = genruntime.ClonePointerToString(source.CreatedDate)

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

	// EndDate
	subscription.EndDate = genruntime.ClonePointerToString(source.EndDate)

	// ExpirationDate
	subscription.ExpirationDate = genruntime.ClonePointerToString(source.ExpirationDate)

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

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

	// NotificationDate
	subscription.NotificationDate = genruntime.ClonePointerToString(source.NotificationDate)

	// OwnerId
	subscription.OwnerId = genruntime.ClonePointerToString(source.OwnerId)

	// Scope
	subscription.Scope = genruntime.ClonePointerToString(source.Scope)

	// StartDate
	subscription.StartDate = genruntime.ClonePointerToString(source.StartDate)

	// State
	subscription.State = genruntime.ClonePointerToString(source.State)

	// StateComment
	subscription.StateComment = genruntime.ClonePointerToString(source.StateComment)

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

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

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

	// No error
	return nil
}

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

	// AllowTracing
	if subscription.AllowTracing != nil {
		allowTracing := *subscription.AllowTracing
		destination.AllowTracing = &allowTracing
	} else {
		destination.AllowTracing = nil
	}

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

	// CreatedDate
	destination.CreatedDate = genruntime.ClonePointerToString(subscription.CreatedDate)

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

	// EndDate
	destination.EndDate = genruntime.ClonePointerToString(subscription.EndDate)

	// ExpirationDate
	destination.ExpirationDate = genruntime.ClonePointerToString(subscription.ExpirationDate)

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

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

	// NotificationDate
	destination.NotificationDate = genruntime.ClonePointerToString(subscription.NotificationDate)

	// OwnerId
	destination.OwnerId = genruntime.ClonePointerToString(subscription.OwnerId)

	// Scope
	destination.Scope = genruntime.ClonePointerToString(subscription.Scope)

	// StartDate
	destination.StartDate = genruntime.ClonePointerToString(subscription.StartDate)

	// State
	destination.State = genruntime.ClonePointerToString(subscription.State)

	// StateComment
	destination.StateComment = genruntime.ClonePointerToString(subscription.StateComment)

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

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

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

	// No error
	return nil
}

type augmentConversionForSubscription_Spec interface {
	AssignPropertiesFrom(src *storage.Subscription_Spec) error
	AssignPropertiesTo(dst *storage.Subscription_Spec) error
}

type augmentConversionForSubscription_STATUS interface {
	AssignPropertiesFrom(src *storage.Subscription_STATUS) error
	AssignPropertiesTo(dst *storage.Subscription_STATUS) error
}

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

// AssignProperties_From_SubscriptionOperatorSpec populates our SubscriptionOperatorSpec from the provided source SubscriptionOperatorSpec
func (operator *SubscriptionOperatorSpec) AssignProperties_From_SubscriptionOperatorSpec(source *storage.SubscriptionOperatorSpec) 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
	}

	// Secrets
	if source.Secrets != nil {
		var secret SubscriptionOperatorSecrets
		err := secret.AssignProperties_From_SubscriptionOperatorSecrets(source.Secrets)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_SubscriptionOperatorSecrets() to populate field Secrets")
		}
		operator.Secrets = &secret
	} else {
		operator.Secrets = nil
	}

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

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

	// No error
	return nil
}

// AssignProperties_To_SubscriptionOperatorSpec populates the provided destination SubscriptionOperatorSpec from our SubscriptionOperatorSpec
func (operator *SubscriptionOperatorSpec) AssignProperties_To_SubscriptionOperatorSpec(destination *storage.SubscriptionOperatorSpec) 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
	}

	// Secrets
	if operator.Secrets != nil {
		var secret storage.SubscriptionOperatorSecrets
		err := operator.Secrets.AssignProperties_To_SubscriptionOperatorSecrets(&secret)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_SubscriptionOperatorSecrets() to populate field Secrets")
		}
		destination.Secrets = &secret
	} else {
		destination.Secrets = nil
	}

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

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

	// No error
	return nil
}

type augmentConversionForSubscriptionOperatorSpec interface {
	AssignPropertiesFrom(src *storage.SubscriptionOperatorSpec) error
	AssignPropertiesTo(dst *storage.SubscriptionOperatorSpec) error
}

// Storage version of v1api20230501preview.SubscriptionOperatorSecrets
type SubscriptionOperatorSecrets struct {
	PrimaryKey   *genruntime.SecretDestination `json:"primaryKey,omitempty"`
	PropertyBag  genruntime.PropertyBag        `json:"$propertyBag,omitempty"`
	SecondaryKey *genruntime.SecretDestination `json:"secondaryKey,omitempty"`
}

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

	// PrimaryKey
	if source.PrimaryKey != nil {
		primaryKey := source.PrimaryKey.Copy()
		secrets.PrimaryKey = &primaryKey
	} else {
		secrets.PrimaryKey = nil
	}

	// SecondaryKey
	if source.SecondaryKey != nil {
		secondaryKey := source.SecondaryKey.Copy()
		secrets.SecondaryKey = &secondaryKey
	} else {
		secrets.SecondaryKey = nil
	}

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

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

	// No error
	return nil
}

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

	// PrimaryKey
	if secrets.PrimaryKey != nil {
		primaryKey := secrets.PrimaryKey.Copy()
		destination.PrimaryKey = &primaryKey
	} else {
		destination.PrimaryKey = nil
	}

	// SecondaryKey
	if secrets.SecondaryKey != nil {
		secondaryKey := secrets.SecondaryKey.Copy()
		destination.SecondaryKey = &secondaryKey
	} else {
		destination.SecondaryKey = nil
	}

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

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

	// No error
	return nil
}

type augmentConversionForSubscriptionOperatorSecrets interface {
	AssignPropertiesFrom(src *storage.SubscriptionOperatorSecrets) error
	AssignPropertiesTo(dst *storage.SubscriptionOperatorSecrets) error
}

func init() {
	SchemeBuilder.Register(&Subscription{}, &SubscriptionList{})
}
