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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/containerregistry/v1api20230701/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/containerregistry/v1api20230701/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,containerregistry}
// +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: /containerregistry/resource-manager/Microsoft.ContainerRegistry/Registry/stable/2023-07-01/containerregistry.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/replications/{replicationName}
type RegistryReplication struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              RegistryReplication_Spec   `json:"spec,omitempty"`
	Status            RegistryReplication_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &RegistryReplication{}

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

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

var _ conversion.Convertible = &RegistryReplication{}

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

	return replication.AssignProperties_From_RegistryReplication(source)
}

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

	return replication.AssignProperties_To_RegistryReplication(destination)
}

var _ configmaps.Exporter = &RegistryReplication{}

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

var _ secrets.Exporter = &RegistryReplication{}

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

var _ genruntime.ImportableResource = &RegistryReplication{}

// InitializeSpec initializes the spec for this resource from the given status
func (replication *RegistryReplication) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*RegistryReplication_STATUS); ok {
		return replication.Spec.Initialize_From_RegistryReplication_STATUS(s)
	}

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

var _ genruntime.KubernetesResource = &RegistryReplication{}

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

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

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.ContainerRegistry/registries/replications"
func (replication *RegistryReplication) GetType() string {
	return "Microsoft.ContainerRegistry/registries/replications"
}

// NewEmptyStatus returns a new empty (blank) status
func (replication *RegistryReplication) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &RegistryReplication_STATUS{}
}

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

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

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

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

	replication.Status = st
	return nil
}

// AssignProperties_From_RegistryReplication populates our RegistryReplication from the provided source RegistryReplication
func (replication *RegistryReplication) AssignProperties_From_RegistryReplication(source *storage.RegistryReplication) error {

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

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

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

	// No error
	return nil
}

// AssignProperties_To_RegistryReplication populates the provided destination RegistryReplication from our RegistryReplication
func (replication *RegistryReplication) AssignProperties_To_RegistryReplication(destination *storage.RegistryReplication) error {

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

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

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

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /containerregistry/resource-manager/Microsoft.ContainerRegistry/Registry/stable/2023-07-01/containerregistry.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/replications/{replicationName}
type RegistryReplicationList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []RegistryReplication `json:"items"`
}

type RegistryReplication_Spec struct {
	// +kubebuilder:validation:MaxLength=50
	// +kubebuilder:validation:MinLength=5
	// +kubebuilder:validation:Pattern="^[a-zA-Z0-9]*$"
	// 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
	// Location: The location of the resource. This cannot be changed after the resource is created.
	Location *string `json:"location,omitempty"`

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

	// RegionEndpointEnabled: Specifies whether the replication's regional endpoint is enabled. Requests will not be routed to
	// a replication whose regional endpoint is disabled, however its data will continue to be synced with other replications.
	RegionEndpointEnabled *bool `json:"regionEndpointEnabled,omitempty"`

	// Tags: The tags of the resource.
	Tags map[string]string `json:"tags,omitempty"`

	// ZoneRedundancy: Whether or not zone redundancy is enabled for this container registry replication
	ZoneRedundancy *ReplicationProperties_ZoneRedundancy `json:"zoneRedundancy,omitempty"`
}

var _ genruntime.ARMTransformer = &RegistryReplication_Spec{}

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

	// Set property "Location":
	if replication.Location != nil {
		location := *replication.Location
		result.Location = &location
	}

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

	// Set property "Properties":
	if replication.RegionEndpointEnabled != nil || replication.ZoneRedundancy != nil {
		result.Properties = &arm.ReplicationProperties{}
	}
	if replication.RegionEndpointEnabled != nil {
		regionEndpointEnabled := *replication.RegionEndpointEnabled
		result.Properties.RegionEndpointEnabled = &regionEndpointEnabled
	}
	if replication.ZoneRedundancy != nil {
		var temp string
		temp = string(*replication.ZoneRedundancy)
		zoneRedundancy := arm.ReplicationProperties_ZoneRedundancy(temp)
		result.Properties.ZoneRedundancy = &zoneRedundancy
	}

	// Set property "Tags":
	if replication.Tags != nil {
		result.Tags = make(map[string]string, len(replication.Tags))
		for key, value := range replication.Tags {
			result.Tags[key] = value
		}
	}
	return result, nil
}

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

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

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

	// Set property "Location":
	if typedInput.Location != nil {
		location := *typedInput.Location
		replication.Location = &location
	}

	// no assignment for property "OperatorSpec"

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

	// Set property "RegionEndpointEnabled":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RegionEndpointEnabled != nil {
			regionEndpointEnabled := *typedInput.Properties.RegionEndpointEnabled
			replication.RegionEndpointEnabled = &regionEndpointEnabled
		}
	}

	// Set property "Tags":
	if typedInput.Tags != nil {
		replication.Tags = make(map[string]string, len(typedInput.Tags))
		for key, value := range typedInput.Tags {
			replication.Tags[key] = value
		}
	}

	// Set property "ZoneRedundancy":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ZoneRedundancy != nil {
			var temp string
			temp = string(*typedInput.Properties.ZoneRedundancy)
			zoneRedundancy := ReplicationProperties_ZoneRedundancy(temp)
			replication.ZoneRedundancy = &zoneRedundancy
		}
	}

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &RegistryReplication_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.RegistryReplication_Spec{}
	err := replication.AssignProperties_To_RegistryReplication_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_RegistryReplication_Spec populates our RegistryReplication_Spec from the provided source RegistryReplication_Spec
func (replication *RegistryReplication_Spec) AssignProperties_From_RegistryReplication_Spec(source *storage.RegistryReplication_Spec) error {

	// AzureName
	replication.AzureName = source.AzureName

	// Location
	replication.Location = genruntime.ClonePointerToString(source.Location)

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

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

	// RegionEndpointEnabled
	if source.RegionEndpointEnabled != nil {
		regionEndpointEnabled := *source.RegionEndpointEnabled
		replication.RegionEndpointEnabled = &regionEndpointEnabled
	} else {
		replication.RegionEndpointEnabled = nil
	}

	// Tags
	replication.Tags = genruntime.CloneMapOfStringToString(source.Tags)

	// ZoneRedundancy
	if source.ZoneRedundancy != nil {
		zoneRedundancy := *source.ZoneRedundancy
		zoneRedundancyTemp := genruntime.ToEnum(zoneRedundancy, replicationProperties_ZoneRedundancy_Values)
		replication.ZoneRedundancy = &zoneRedundancyTemp
	} else {
		replication.ZoneRedundancy = nil
	}

	// No error
	return nil
}

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

	// AzureName
	destination.AzureName = replication.AzureName

	// Location
	destination.Location = genruntime.ClonePointerToString(replication.Location)

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

	// OriginalVersion
	destination.OriginalVersion = replication.OriginalVersion()

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

	// RegionEndpointEnabled
	if replication.RegionEndpointEnabled != nil {
		regionEndpointEnabled := *replication.RegionEndpointEnabled
		destination.RegionEndpointEnabled = &regionEndpointEnabled
	} else {
		destination.RegionEndpointEnabled = nil
	}

	// Tags
	destination.Tags = genruntime.CloneMapOfStringToString(replication.Tags)

	// ZoneRedundancy
	if replication.ZoneRedundancy != nil {
		zoneRedundancy := string(*replication.ZoneRedundancy)
		destination.ZoneRedundancy = &zoneRedundancy
	} else {
		destination.ZoneRedundancy = nil
	}

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

	// No error
	return nil
}

// Initialize_From_RegistryReplication_STATUS populates our RegistryReplication_Spec from the provided source RegistryReplication_STATUS
func (replication *RegistryReplication_Spec) Initialize_From_RegistryReplication_STATUS(source *RegistryReplication_STATUS) error {

	// Location
	replication.Location = genruntime.ClonePointerToString(source.Location)

	// RegionEndpointEnabled
	if source.RegionEndpointEnabled != nil {
		regionEndpointEnabled := *source.RegionEndpointEnabled
		replication.RegionEndpointEnabled = &regionEndpointEnabled
	} else {
		replication.RegionEndpointEnabled = nil
	}

	// Tags
	replication.Tags = genruntime.CloneMapOfStringToString(source.Tags)

	// ZoneRedundancy
	if source.ZoneRedundancy != nil {
		zoneRedundancy := genruntime.ToEnum(string(*source.ZoneRedundancy), replicationProperties_ZoneRedundancy_Values)
		replication.ZoneRedundancy = &zoneRedundancy
	} else {
		replication.ZoneRedundancy = nil
	}

	// No error
	return nil
}

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

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

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

	// Id: The resource ID.
	Id *string `json:"id,omitempty"`

	// Location: The location of the resource. This cannot be changed after the resource is created.
	Location *string `json:"location,omitempty"`

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

	// ProvisioningState: The provisioning state of the replication at the time the operation was called.
	ProvisioningState *ReplicationProperties_ProvisioningState_STATUS `json:"provisioningState,omitempty"`

	// RegionEndpointEnabled: Specifies whether the replication's regional endpoint is enabled. Requests will not be routed to
	// a replication whose regional endpoint is disabled, however its data will continue to be synced with other replications.
	RegionEndpointEnabled *bool `json:"regionEndpointEnabled,omitempty"`

	// Status: The status of the replication at the time the operation was called.
	Status *Status_STATUS `json:"status,omitempty"`

	// SystemData: Metadata pertaining to creation and last modification of the resource.
	SystemData *SystemData_STATUS `json:"systemData,omitempty"`

	// Tags: The tags of the resource.
	Tags map[string]string `json:"tags,omitempty"`

	// Type: The type of the resource.
	Type *string `json:"type,omitempty"`

	// ZoneRedundancy: Whether or not zone redundancy is enabled for this container registry replication
	ZoneRedundancy *ReplicationProperties_ZoneRedundancy_STATUS `json:"zoneRedundancy,omitempty"`
}

var _ genruntime.ConvertibleStatus = &RegistryReplication_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.RegistryReplication_STATUS{}
	err := replication.AssignProperties_To_RegistryReplication_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 = &RegistryReplication_STATUS{}

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

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

	// no assignment for property "Conditions"

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

	// Set property "Location":
	if typedInput.Location != nil {
		location := *typedInput.Location
		replication.Location = &location
	}

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

	// Set property "ProvisioningState":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ProvisioningState != nil {
			var temp string
			temp = string(*typedInput.Properties.ProvisioningState)
			provisioningState := ReplicationProperties_ProvisioningState_STATUS(temp)
			replication.ProvisioningState = &provisioningState
		}
	}

	// Set property "RegionEndpointEnabled":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RegionEndpointEnabled != nil {
			regionEndpointEnabled := *typedInput.Properties.RegionEndpointEnabled
			replication.RegionEndpointEnabled = &regionEndpointEnabled
		}
	}

	// Set property "Status":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Status != nil {
			var status1 Status_STATUS
			err := status1.PopulateFromARM(owner, *typedInput.Properties.Status)
			if err != nil {
				return err
			}
			status := status1
			replication.Status = &status
		}
	}

	// Set property "SystemData":
	if typedInput.SystemData != nil {
		var systemData1 SystemData_STATUS
		err := systemData1.PopulateFromARM(owner, *typedInput.SystemData)
		if err != nil {
			return err
		}
		systemData := systemData1
		replication.SystemData = &systemData
	}

	// Set property "Tags":
	if typedInput.Tags != nil {
		replication.Tags = make(map[string]string, len(typedInput.Tags))
		for key, value := range typedInput.Tags {
			replication.Tags[key] = value
		}
	}

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

	// Set property "ZoneRedundancy":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ZoneRedundancy != nil {
			var temp string
			temp = string(*typedInput.Properties.ZoneRedundancy)
			zoneRedundancy := ReplicationProperties_ZoneRedundancy_STATUS(temp)
			replication.ZoneRedundancy = &zoneRedundancy
		}
	}

	// No error
	return nil
}

// AssignProperties_From_RegistryReplication_STATUS populates our RegistryReplication_STATUS from the provided source RegistryReplication_STATUS
func (replication *RegistryReplication_STATUS) AssignProperties_From_RegistryReplication_STATUS(source *storage.RegistryReplication_STATUS) error {

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

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

	// Location
	replication.Location = genruntime.ClonePointerToString(source.Location)

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

	// ProvisioningState
	if source.ProvisioningState != nil {
		provisioningState := *source.ProvisioningState
		provisioningStateTemp := genruntime.ToEnum(provisioningState, replicationProperties_ProvisioningState_STATUS_Values)
		replication.ProvisioningState = &provisioningStateTemp
	} else {
		replication.ProvisioningState = nil
	}

	// RegionEndpointEnabled
	if source.RegionEndpointEnabled != nil {
		regionEndpointEnabled := *source.RegionEndpointEnabled
		replication.RegionEndpointEnabled = &regionEndpointEnabled
	} else {
		replication.RegionEndpointEnabled = nil
	}

	// Status
	if source.Status != nil {
		var status Status_STATUS
		err := status.AssignProperties_From_Status_STATUS(source.Status)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_Status_STATUS() to populate field Status")
		}
		replication.Status = &status
	} else {
		replication.Status = nil
	}

	// SystemData
	if source.SystemData != nil {
		var systemDatum SystemData_STATUS
		err := systemDatum.AssignProperties_From_SystemData_STATUS(source.SystemData)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_SystemData_STATUS() to populate field SystemData")
		}
		replication.SystemData = &systemDatum
	} else {
		replication.SystemData = nil
	}

	// Tags
	replication.Tags = genruntime.CloneMapOfStringToString(source.Tags)

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

	// ZoneRedundancy
	if source.ZoneRedundancy != nil {
		zoneRedundancy := *source.ZoneRedundancy
		zoneRedundancyTemp := genruntime.ToEnum(zoneRedundancy, replicationProperties_ZoneRedundancy_STATUS_Values)
		replication.ZoneRedundancy = &zoneRedundancyTemp
	} else {
		replication.ZoneRedundancy = nil
	}

	// No error
	return nil
}

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

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

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

	// Location
	destination.Location = genruntime.ClonePointerToString(replication.Location)

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

	// ProvisioningState
	if replication.ProvisioningState != nil {
		provisioningState := string(*replication.ProvisioningState)
		destination.ProvisioningState = &provisioningState
	} else {
		destination.ProvisioningState = nil
	}

	// RegionEndpointEnabled
	if replication.RegionEndpointEnabled != nil {
		regionEndpointEnabled := *replication.RegionEndpointEnabled
		destination.RegionEndpointEnabled = &regionEndpointEnabled
	} else {
		destination.RegionEndpointEnabled = nil
	}

	// Status
	if replication.Status != nil {
		var status storage.Status_STATUS
		err := replication.Status.AssignProperties_To_Status_STATUS(&status)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_Status_STATUS() to populate field Status")
		}
		destination.Status = &status
	} else {
		destination.Status = nil
	}

	// SystemData
	if replication.SystemData != nil {
		var systemDatum storage.SystemData_STATUS
		err := replication.SystemData.AssignProperties_To_SystemData_STATUS(&systemDatum)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_SystemData_STATUS() to populate field SystemData")
		}
		destination.SystemData = &systemDatum
	} else {
		destination.SystemData = nil
	}

	// Tags
	destination.Tags = genruntime.CloneMapOfStringToString(replication.Tags)

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

	// ZoneRedundancy
	if replication.ZoneRedundancy != nil {
		zoneRedundancy := string(*replication.ZoneRedundancy)
		destination.ZoneRedundancy = &zoneRedundancy
	} else {
		destination.ZoneRedundancy = nil
	}

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

	// No error
	return nil
}

// Details for configuring operator behavior. Fields in this struct are interpreted by the operator directly rather than being passed to Azure
type RegistryReplicationOperatorSpec 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_RegistryReplicationOperatorSpec populates our RegistryReplicationOperatorSpec from the provided source RegistryReplicationOperatorSpec
func (operator *RegistryReplicationOperatorSpec) AssignProperties_From_RegistryReplicationOperatorSpec(source *storage.RegistryReplicationOperatorSpec) 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_RegistryReplicationOperatorSpec populates the provided destination RegistryReplicationOperatorSpec from our RegistryReplicationOperatorSpec
func (operator *RegistryReplicationOperatorSpec) AssignProperties_To_RegistryReplicationOperatorSpec(destination *storage.RegistryReplicationOperatorSpec) 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
}

type ReplicationProperties_ProvisioningState_STATUS string

const (
	ReplicationProperties_ProvisioningState_STATUS_Canceled  = ReplicationProperties_ProvisioningState_STATUS("Canceled")
	ReplicationProperties_ProvisioningState_STATUS_Creating  = ReplicationProperties_ProvisioningState_STATUS("Creating")
	ReplicationProperties_ProvisioningState_STATUS_Deleting  = ReplicationProperties_ProvisioningState_STATUS("Deleting")
	ReplicationProperties_ProvisioningState_STATUS_Failed    = ReplicationProperties_ProvisioningState_STATUS("Failed")
	ReplicationProperties_ProvisioningState_STATUS_Succeeded = ReplicationProperties_ProvisioningState_STATUS("Succeeded")
	ReplicationProperties_ProvisioningState_STATUS_Updating  = ReplicationProperties_ProvisioningState_STATUS("Updating")
)

// Mapping from string to ReplicationProperties_ProvisioningState_STATUS
var replicationProperties_ProvisioningState_STATUS_Values = map[string]ReplicationProperties_ProvisioningState_STATUS{
	"canceled":  ReplicationProperties_ProvisioningState_STATUS_Canceled,
	"creating":  ReplicationProperties_ProvisioningState_STATUS_Creating,
	"deleting":  ReplicationProperties_ProvisioningState_STATUS_Deleting,
	"failed":    ReplicationProperties_ProvisioningState_STATUS_Failed,
	"succeeded": ReplicationProperties_ProvisioningState_STATUS_Succeeded,
	"updating":  ReplicationProperties_ProvisioningState_STATUS_Updating,
}

// +kubebuilder:validation:Enum={"Disabled","Enabled"}
type ReplicationProperties_ZoneRedundancy string

const (
	ReplicationProperties_ZoneRedundancy_Disabled = ReplicationProperties_ZoneRedundancy("Disabled")
	ReplicationProperties_ZoneRedundancy_Enabled  = ReplicationProperties_ZoneRedundancy("Enabled")
)

// Mapping from string to ReplicationProperties_ZoneRedundancy
var replicationProperties_ZoneRedundancy_Values = map[string]ReplicationProperties_ZoneRedundancy{
	"disabled": ReplicationProperties_ZoneRedundancy_Disabled,
	"enabled":  ReplicationProperties_ZoneRedundancy_Enabled,
}

type ReplicationProperties_ZoneRedundancy_STATUS string

const (
	ReplicationProperties_ZoneRedundancy_STATUS_Disabled = ReplicationProperties_ZoneRedundancy_STATUS("Disabled")
	ReplicationProperties_ZoneRedundancy_STATUS_Enabled  = ReplicationProperties_ZoneRedundancy_STATUS("Enabled")
)

// Mapping from string to ReplicationProperties_ZoneRedundancy_STATUS
var replicationProperties_ZoneRedundancy_STATUS_Values = map[string]ReplicationProperties_ZoneRedundancy_STATUS{
	"disabled": ReplicationProperties_ZoneRedundancy_STATUS_Disabled,
	"enabled":  ReplicationProperties_ZoneRedundancy_STATUS_Enabled,
}

func init() {
	SchemeBuilder.Register(&RegistryReplication{}, &RegistryReplicationList{})
}
