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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601/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,resources}
// +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: /resources/resource-manager/Microsoft.Resources/stable/2020-06-01/resources.json
// - ARM URI: /subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}
type ResourceGroup struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              ResourceGroup_Spec   `json:"spec,omitempty"`
	Status            ResourceGroup_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &ResourceGroup{}

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

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

var _ conversion.Convertible = &ResourceGroup{}

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

	return group.AssignProperties_From_ResourceGroup(source)
}

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

	return group.AssignProperties_To_ResourceGroup(destination)
}

var _ configmaps.Exporter = &ResourceGroup{}

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

var _ secrets.Exporter = &ResourceGroup{}

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

var _ genruntime.ImportableResource = &ResourceGroup{}

// InitializeSpec initializes the spec for this resource from the given status
func (group *ResourceGroup) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*ResourceGroup_STATUS); ok {
		return group.Spec.Initialize_From_ResourceGroup_STATUS(s)
	}

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

var _ genruntime.KubernetesResource = &ResourceGroup{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2020-06-01"
func (group ResourceGroup) GetAPIVersion() string {
	return "2020-06-01"
}

// GetResourceScope returns the scope of the resource
func (group *ResourceGroup) GetResourceScope() genruntime.ResourceScope {
	return genruntime.ResourceScopeLocation
}

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

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

// GetSupportedOperations returns the operations supported by the resource
func (group *ResourceGroup) 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.Resources/resourceGroups"
func (group *ResourceGroup) GetType() string {
	return "Microsoft.Resources/resourceGroups"
}

// NewEmptyStatus returns a new empty (blank) status
func (group *ResourceGroup) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &ResourceGroup_STATUS{}
}

// Owner returns nil as Location scoped resources never have an owner
func (group *ResourceGroup) Owner() *genruntime.ResourceReference {
	return nil
}

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

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

	group.Status = st
	return nil
}

var _ genruntime.LocatableResource = &ResourceGroup{}

// Location returns the location of the resource
func (group *ResourceGroup) Location() string {
	if group.Spec.Location == nil {
		return ""
	}
	return *group.Spec.Location
}

// AssignProperties_From_ResourceGroup populates our ResourceGroup from the provided source ResourceGroup
func (group *ResourceGroup) AssignProperties_From_ResourceGroup(source *storage.ResourceGroup) error {

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

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

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

	// No error
	return nil
}

// AssignProperties_To_ResourceGroup populates the provided destination ResourceGroup from our ResourceGroup
func (group *ResourceGroup) AssignProperties_To_ResourceGroup(destination *storage.ResourceGroup) error {

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

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

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

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /resources/resource-manager/Microsoft.Resources/stable/2020-06-01/resources.json
// - ARM URI: /subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}
type ResourceGroupList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []ResourceGroup `json:"items"`
}

// +kubebuilder:validation:Enum={"2020-06-01"}
type APIVersion string

const APIVersion_Value = APIVersion("2020-06-01")

type ResourceGroup_Spec struct {
	// +kubebuilder:validation:MaxLength=90
	// +kubebuilder:validation:MinLength=1
	// 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 group. It cannot be changed after the resource group has been created. It must be
	// one of the supported Azure locations.
	Location *string `json:"location,omitempty"`

	// ManagedBy: The ID of the resource that manages this resource group.
	ManagedBy *string `json:"managedBy,omitempty"`

	// OperatorSpec: The specification for configuring operator behavior. This field is interpreted by the operator and not
	// passed directly to Azure
	OperatorSpec *ResourceGroupOperatorSpec `json:"operatorSpec,omitempty"`

	// Tags: The tags attached to the resource group.
	Tags map[string]string `json:"tags,omitempty"`
}

var _ genruntime.ARMTransformer = &ResourceGroup_Spec{}

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

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

	// Set property "ManagedBy":
	if group.ManagedBy != nil {
		managedBy := *group.ManagedBy
		result.ManagedBy = &managedBy
	}

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

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

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

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

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

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

	// Set property "ManagedBy":
	if typedInput.ManagedBy != nil {
		managedBy := *typedInput.ManagedBy
		group.ManagedBy = &managedBy
	}

	// no assignment for property "OperatorSpec"

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

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &ResourceGroup_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.ResourceGroup_Spec{}
	err := group.AssignProperties_To_ResourceGroup_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_ResourceGroup_Spec populates our ResourceGroup_Spec from the provided source ResourceGroup_Spec
func (group *ResourceGroup_Spec) AssignProperties_From_ResourceGroup_Spec(source *storage.ResourceGroup_Spec) error {

	// AzureName
	group.AzureName = source.AzureName

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

	// ManagedBy
	group.ManagedBy = genruntime.ClonePointerToString(source.ManagedBy)

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

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

	// No error
	return nil
}

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

	// AzureName
	destination.AzureName = group.AzureName

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

	// ManagedBy
	destination.ManagedBy = genruntime.ClonePointerToString(group.ManagedBy)

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

	// OriginalVersion
	destination.OriginalVersion = group.OriginalVersion()

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

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

	// No error
	return nil
}

// Initialize_From_ResourceGroup_STATUS populates our ResourceGroup_Spec from the provided source ResourceGroup_STATUS
func (group *ResourceGroup_Spec) Initialize_From_ResourceGroup_STATUS(source *ResourceGroup_STATUS) error {

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

	// ManagedBy
	group.ManagedBy = genruntime.ClonePointerToString(source.ManagedBy)

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

	// No error
	return nil
}

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

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

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

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

	// Location: The location of the resource group. It cannot be changed after the resource group has been created. It must be
	// one of the supported Azure locations.
	Location *string `json:"location,omitempty"`

	// ManagedBy: The ID of the resource that manages this resource group.
	ManagedBy *string `json:"managedBy,omitempty"`

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

	// Properties: The resource group properties.
	Properties *ResourceGroupProperties_STATUS `json:"properties,omitempty"`

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

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

var _ genruntime.ConvertibleStatus = &ResourceGroup_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.ResourceGroup_STATUS{}
	err := group.AssignProperties_To_ResourceGroup_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 = &ResourceGroup_STATUS{}

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

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

	// no assignment for property "Conditions"

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

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

	// Set property "ManagedBy":
	if typedInput.ManagedBy != nil {
		managedBy := *typedInput.ManagedBy
		group.ManagedBy = &managedBy
	}

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

	// Set property "Properties":
	if typedInput.Properties != nil {
		var properties1 ResourceGroupProperties_STATUS
		err := properties1.PopulateFromARM(owner, *typedInput.Properties)
		if err != nil {
			return err
		}
		properties := properties1
		group.Properties = &properties
	}

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

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

	// No error
	return nil
}

// AssignProperties_From_ResourceGroup_STATUS populates our ResourceGroup_STATUS from the provided source ResourceGroup_STATUS
func (group *ResourceGroup_STATUS) AssignProperties_From_ResourceGroup_STATUS(source *storage.ResourceGroup_STATUS) error {

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

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

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

	// ManagedBy
	group.ManagedBy = genruntime.ClonePointerToString(source.ManagedBy)

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

	// Properties
	if source.Properties != nil {
		var property ResourceGroupProperties_STATUS
		err := property.AssignProperties_From_ResourceGroupProperties_STATUS(source.Properties)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_ResourceGroupProperties_STATUS() to populate field Properties")
		}
		group.Properties = &property
	} else {
		group.Properties = nil
	}

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

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

	// No error
	return nil
}

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

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

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

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

	// ManagedBy
	destination.ManagedBy = genruntime.ClonePointerToString(group.ManagedBy)

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

	// Properties
	if group.Properties != nil {
		var property storage.ResourceGroupProperties_STATUS
		err := group.Properties.AssignProperties_To_ResourceGroupProperties_STATUS(&property)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_ResourceGroupProperties_STATUS() to populate field Properties")
		}
		destination.Properties = &property
	} else {
		destination.Properties = nil
	}

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

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

	// 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 ResourceGroupOperatorSpec 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_ResourceGroupOperatorSpec populates our ResourceGroupOperatorSpec from the provided source ResourceGroupOperatorSpec
func (operator *ResourceGroupOperatorSpec) AssignProperties_From_ResourceGroupOperatorSpec(source *storage.ResourceGroupOperatorSpec) 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_ResourceGroupOperatorSpec populates the provided destination ResourceGroupOperatorSpec from our ResourceGroupOperatorSpec
func (operator *ResourceGroupOperatorSpec) AssignProperties_To_ResourceGroupOperatorSpec(destination *storage.ResourceGroupOperatorSpec) 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
}

// The resource group properties.
type ResourceGroupProperties_STATUS struct {
	// ProvisioningState: The provisioning state.
	ProvisioningState *string `json:"provisioningState,omitempty"`
}

var _ genruntime.FromARMConverter = &ResourceGroupProperties_STATUS{}

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

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

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

	// No error
	return nil
}

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

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

	// No error
	return nil
}

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

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

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

	// No error
	return nil
}

func init() {
	SchemeBuilder.Register(&ResourceGroup{}, &ResourceGroupList{})
}
