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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/authorization/v1api20220401/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/authorization/v1api20220401/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,authorization}
// +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: /authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/authorization-RoleDefinitionsCalls.json
// - ARM URI: /{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionId}
type RoleDefinition struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              RoleDefinition_Spec   `json:"spec,omitempty"`
	Status            RoleDefinition_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &RoleDefinition{}

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

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

var _ conversion.Convertible = &RoleDefinition{}

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

	return definition.AssignProperties_From_RoleDefinition(source)
}

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

	return definition.AssignProperties_To_RoleDefinition(destination)
}

var _ configmaps.Exporter = &RoleDefinition{}

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

var _ secrets.Exporter = &RoleDefinition{}

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

var _ genruntime.ImportableResource = &RoleDefinition{}

// InitializeSpec initializes the spec for this resource from the given status
func (definition *RoleDefinition) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*RoleDefinition_STATUS); ok {
		return definition.Spec.Initialize_From_RoleDefinition_STATUS(s)
	}

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

var _ genruntime.KubernetesResource = &RoleDefinition{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2022-04-01"
func (definition RoleDefinition) GetAPIVersion() string {
	return "2022-04-01"
}

// GetResourceScope returns the scope of the resource
func (definition *RoleDefinition) GetResourceScope() genruntime.ResourceScope {
	return genruntime.ResourceScopeExtension
}

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.Authorization/roleDefinitions"
func (definition *RoleDefinition) GetType() string {
	return "Microsoft.Authorization/roleDefinitions"
}

// NewEmptyStatus returns a new empty (blank) status
func (definition *RoleDefinition) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &RoleDefinition_STATUS{}
}

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

	return definition.Spec.Owner.AsResourceReference()
}

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

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

	definition.Status = st
	return nil
}

// AssignProperties_From_RoleDefinition populates our RoleDefinition from the provided source RoleDefinition
func (definition *RoleDefinition) AssignProperties_From_RoleDefinition(source *storage.RoleDefinition) error {

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

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

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

	// No error
	return nil
}

// AssignProperties_To_RoleDefinition populates the provided destination RoleDefinition from our RoleDefinition
func (definition *RoleDefinition) AssignProperties_To_RoleDefinition(destination *storage.RoleDefinition) error {

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

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

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

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /authorization/resource-manager/Microsoft.Authorization/stable/2022-04-01/authorization-RoleDefinitionsCalls.json
// - ARM URI: /{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionId}
type RoleDefinitionList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []RoleDefinition `json:"items"`
}

type RoleDefinition_Spec struct {
	// AssignableScopesReferences: Role definition assignable scopes.
	AssignableScopesReferences []genruntime.ResourceReference `armReference:"AssignableScopes" json:"assignableScopesReferences,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"`

	// Description: The role definition description.
	Description *string `json:"description,omitempty"`

	// OperatorSpec: The specification for configuring operator behavior. This field is interpreted by the operator and not
	// passed directly to Azure
	OperatorSpec *RoleDefinitionOperatorSpec `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. This resource is an
	// extension resource, which means that any other Azure resource can be its owner.
	Owner *genruntime.ArbitraryOwnerReference `json:"owner,omitempty"`

	// Permissions: Role definition permissions.
	Permissions []Permission `json:"permissions,omitempty"`

	// RoleName: The role name.
	RoleName *string `json:"roleName,omitempty"`

	// Type: The role type.
	Type *string `json:"type,omitempty"`
}

var _ genruntime.ARMTransformer = &RoleDefinition_Spec{}

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

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

	// Set property "Properties":
	if definition.AssignableScopesReferences != nil ||
		definition.Description != nil ||
		definition.Permissions != nil ||
		definition.RoleName != nil ||
		definition.Type != nil {
		result.Properties = &arm.RoleDefinitionProperties{}
	}
	for _, item := range definition.AssignableScopesReferences {
		itemARMID, err := resolved.ResolvedReferences.Lookup(item)
		if err != nil {
			return nil, err
		}
		result.Properties.AssignableScopes = append(result.Properties.AssignableScopes, itemARMID)
	}
	if definition.Description != nil {
		description := *definition.Description
		result.Properties.Description = &description
	}
	for _, item := range definition.Permissions {
		item_ARM, err := item.ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		result.Properties.Permissions = append(result.Properties.Permissions, *item_ARM.(*arm.Permission))
	}
	if definition.RoleName != nil {
		roleName := *definition.RoleName
		result.Properties.RoleName = &roleName
	}
	if definition.Type != nil {
		typeVar := *definition.Type
		result.Properties.Type = &typeVar
	}
	return result, nil
}

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

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

	// no assignment for property "AssignableScopesReferences"

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

	// Set property "Description":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Description != nil {
			description := *typedInput.Properties.Description
			definition.Description = &description
		}
	}

	// no assignment for property "OperatorSpec"

	// Set property "Owner":
	definition.Owner = &owner

	// Set property "Permissions":
	// copying flattened property:
	if typedInput.Properties != nil {
		for _, item := range typedInput.Properties.Permissions {
			var item1 Permission
			err := item1.PopulateFromARM(owner, item)
			if err != nil {
				return err
			}
			definition.Permissions = append(definition.Permissions, item1)
		}
	}

	// Set property "RoleName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RoleName != nil {
			roleName := *typedInput.Properties.RoleName
			definition.RoleName = &roleName
		}
	}

	// Set property "Type":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Type != nil {
			typeVar := *typedInput.Properties.Type
			definition.Type = &typeVar
		}
	}

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &RoleDefinition_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.RoleDefinition_Spec{}
	err := definition.AssignProperties_To_RoleDefinition_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_RoleDefinition_Spec populates our RoleDefinition_Spec from the provided source RoleDefinition_Spec
func (definition *RoleDefinition_Spec) AssignProperties_From_RoleDefinition_Spec(source *storage.RoleDefinition_Spec) error {

	// AssignableScopesReferences
	if source.AssignableScopesReferences != nil {
		assignableScopesReferenceList := make([]genruntime.ResourceReference, len(source.AssignableScopesReferences))
		for assignableScopesReferenceIndex, assignableScopesReferenceItem := range source.AssignableScopesReferences {
			assignableScopesReferenceList[assignableScopesReferenceIndex] = assignableScopesReferenceItem.Copy()
		}
		definition.AssignableScopesReferences = assignableScopesReferenceList
	} else {
		definition.AssignableScopesReferences = nil
	}

	// AzureName
	definition.AzureName = source.AzureName

	// Description
	definition.Description = genruntime.ClonePointerToString(source.Description)

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

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

	// Permissions
	if source.Permissions != nil {
		permissionList := make([]Permission, len(source.Permissions))
		for permissionIndex, permissionItem := range source.Permissions {
			var permission Permission
			err := permission.AssignProperties_From_Permission(&permissionItem)
			if err != nil {
				return eris.Wrap(err, "calling AssignProperties_From_Permission() to populate field Permissions")
			}
			permissionList[permissionIndex] = permission
		}
		definition.Permissions = permissionList
	} else {
		definition.Permissions = nil
	}

	// RoleName
	definition.RoleName = genruntime.ClonePointerToString(source.RoleName)

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

	// No error
	return nil
}

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

	// AssignableScopesReferences
	if definition.AssignableScopesReferences != nil {
		assignableScopesReferenceList := make([]genruntime.ResourceReference, len(definition.AssignableScopesReferences))
		for assignableScopesReferenceIndex, assignableScopesReferenceItem := range definition.AssignableScopesReferences {
			assignableScopesReferenceList[assignableScopesReferenceIndex] = assignableScopesReferenceItem.Copy()
		}
		destination.AssignableScopesReferences = assignableScopesReferenceList
	} else {
		destination.AssignableScopesReferences = nil
	}

	// AzureName
	destination.AzureName = definition.AzureName

	// Description
	destination.Description = genruntime.ClonePointerToString(definition.Description)

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

	// OriginalVersion
	destination.OriginalVersion = definition.OriginalVersion()

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

	// Permissions
	if definition.Permissions != nil {
		permissionList := make([]storage.Permission, len(definition.Permissions))
		for permissionIndex, permissionItem := range definition.Permissions {
			var permission storage.Permission
			err := permissionItem.AssignProperties_To_Permission(&permission)
			if err != nil {
				return eris.Wrap(err, "calling AssignProperties_To_Permission() to populate field Permissions")
			}
			permissionList[permissionIndex] = permission
		}
		destination.Permissions = permissionList
	} else {
		destination.Permissions = nil
	}

	// RoleName
	destination.RoleName = genruntime.ClonePointerToString(definition.RoleName)

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

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

	// No error
	return nil
}

// Initialize_From_RoleDefinition_STATUS populates our RoleDefinition_Spec from the provided source RoleDefinition_STATUS
func (definition *RoleDefinition_Spec) Initialize_From_RoleDefinition_STATUS(source *RoleDefinition_STATUS) error {

	// Description
	definition.Description = genruntime.ClonePointerToString(source.Description)

	// Permissions
	if source.Permissions != nil {
		permissionList := make([]Permission, len(source.Permissions))
		for permissionIndex, permissionItem := range source.Permissions {
			var permission Permission
			err := permission.Initialize_From_Permission_STATUS(&permissionItem)
			if err != nil {
				return eris.Wrap(err, "calling Initialize_From_Permission_STATUS() to populate field Permissions")
			}
			permissionList[permissionIndex] = permission
		}
		definition.Permissions = permissionList
	} else {
		definition.Permissions = nil
	}

	// RoleName
	definition.RoleName = genruntime.ClonePointerToString(source.RoleName)

	// Type
	definition.Type = genruntime.ClonePointerToString(source.PropertiesType)

	// No error
	return nil
}

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

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

// Role definition.
type RoleDefinition_STATUS struct {
	// AssignableScopes: Role definition assignable scopes.
	AssignableScopes []string `json:"assignableScopes,omitempty"`

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

	// CreatedBy: Id of the user who created the assignment
	CreatedBy *string `json:"createdBy,omitempty"`

	// CreatedOn: Time it was created
	CreatedOn *string `json:"createdOn,omitempty"`

	// Description: The role definition description.
	Description *string `json:"description,omitempty"`

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

	// Name: The role definition name.
	Name *string `json:"name,omitempty"`

	// Permissions: Role definition permissions.
	Permissions []Permission_STATUS `json:"permissions,omitempty"`

	// PropertiesType: The role type.
	PropertiesType *string `json:"properties_type,omitempty"`

	// RoleName: The role name.
	RoleName *string `json:"roleName,omitempty"`

	// Type: The role definition type.
	Type *string `json:"type,omitempty"`

	// UpdatedBy: Id of the user who updated the assignment
	UpdatedBy *string `json:"updatedBy,omitempty"`

	// UpdatedOn: Time it was updated
	UpdatedOn *string `json:"updatedOn,omitempty"`
}

var _ genruntime.ConvertibleStatus = &RoleDefinition_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.RoleDefinition_STATUS{}
	err := definition.AssignProperties_To_RoleDefinition_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 = &RoleDefinition_STATUS{}

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

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

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

	// no assignment for property "Conditions"

	// Set property "CreatedBy":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.CreatedBy != nil {
			createdBy := *typedInput.Properties.CreatedBy
			definition.CreatedBy = &createdBy
		}
	}

	// Set property "CreatedOn":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.CreatedOn != nil {
			createdOn := *typedInput.Properties.CreatedOn
			definition.CreatedOn = &createdOn
		}
	}

	// Set property "Description":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Description != nil {
			description := *typedInput.Properties.Description
			definition.Description = &description
		}
	}

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

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

	// Set property "Permissions":
	// copying flattened property:
	if typedInput.Properties != nil {
		for _, item := range typedInput.Properties.Permissions {
			var item1 Permission_STATUS
			err := item1.PopulateFromARM(owner, item)
			if err != nil {
				return err
			}
			definition.Permissions = append(definition.Permissions, item1)
		}
	}

	// Set property "PropertiesType":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Type != nil {
			propertiesType := *typedInput.Properties.Type
			definition.PropertiesType = &propertiesType
		}
	}

	// Set property "RoleName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RoleName != nil {
			roleName := *typedInput.Properties.RoleName
			definition.RoleName = &roleName
		}
	}

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

	// Set property "UpdatedBy":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.UpdatedBy != nil {
			updatedBy := *typedInput.Properties.UpdatedBy
			definition.UpdatedBy = &updatedBy
		}
	}

	// Set property "UpdatedOn":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.UpdatedOn != nil {
			updatedOn := *typedInput.Properties.UpdatedOn
			definition.UpdatedOn = &updatedOn
		}
	}

	// No error
	return nil
}

// AssignProperties_From_RoleDefinition_STATUS populates our RoleDefinition_STATUS from the provided source RoleDefinition_STATUS
func (definition *RoleDefinition_STATUS) AssignProperties_From_RoleDefinition_STATUS(source *storage.RoleDefinition_STATUS) error {

	// AssignableScopes
	definition.AssignableScopes = genruntime.CloneSliceOfString(source.AssignableScopes)

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

	// CreatedBy
	definition.CreatedBy = genruntime.ClonePointerToString(source.CreatedBy)

	// CreatedOn
	definition.CreatedOn = genruntime.ClonePointerToString(source.CreatedOn)

	// Description
	definition.Description = genruntime.ClonePointerToString(source.Description)

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

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

	// Permissions
	if source.Permissions != nil {
		permissionList := make([]Permission_STATUS, len(source.Permissions))
		for permissionIndex, permissionItem := range source.Permissions {
			var permission Permission_STATUS
			err := permission.AssignProperties_From_Permission_STATUS(&permissionItem)
			if err != nil {
				return eris.Wrap(err, "calling AssignProperties_From_Permission_STATUS() to populate field Permissions")
			}
			permissionList[permissionIndex] = permission
		}
		definition.Permissions = permissionList
	} else {
		definition.Permissions = nil
	}

	// PropertiesType
	definition.PropertiesType = genruntime.ClonePointerToString(source.PropertiesType)

	// RoleName
	definition.RoleName = genruntime.ClonePointerToString(source.RoleName)

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

	// UpdatedBy
	definition.UpdatedBy = genruntime.ClonePointerToString(source.UpdatedBy)

	// UpdatedOn
	definition.UpdatedOn = genruntime.ClonePointerToString(source.UpdatedOn)

	// No error
	return nil
}

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

	// AssignableScopes
	destination.AssignableScopes = genruntime.CloneSliceOfString(definition.AssignableScopes)

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

	// CreatedBy
	destination.CreatedBy = genruntime.ClonePointerToString(definition.CreatedBy)

	// CreatedOn
	destination.CreatedOn = genruntime.ClonePointerToString(definition.CreatedOn)

	// Description
	destination.Description = genruntime.ClonePointerToString(definition.Description)

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

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

	// Permissions
	if definition.Permissions != nil {
		permissionList := make([]storage.Permission_STATUS, len(definition.Permissions))
		for permissionIndex, permissionItem := range definition.Permissions {
			var permission storage.Permission_STATUS
			err := permissionItem.AssignProperties_To_Permission_STATUS(&permission)
			if err != nil {
				return eris.Wrap(err, "calling AssignProperties_To_Permission_STATUS() to populate field Permissions")
			}
			permissionList[permissionIndex] = permission
		}
		destination.Permissions = permissionList
	} else {
		destination.Permissions = nil
	}

	// PropertiesType
	destination.PropertiesType = genruntime.ClonePointerToString(definition.PropertiesType)

	// RoleName
	destination.RoleName = genruntime.ClonePointerToString(definition.RoleName)

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

	// UpdatedBy
	destination.UpdatedBy = genruntime.ClonePointerToString(definition.UpdatedBy)

	// UpdatedOn
	destination.UpdatedOn = genruntime.ClonePointerToString(definition.UpdatedOn)

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

	// No error
	return nil
}

// Role definition permissions.
type Permission struct {
	// Actions: Allowed actions.
	Actions []string `json:"actions,omitempty"`

	// DataActions: Allowed Data actions.
	DataActions []string `json:"dataActions,omitempty"`

	// NotActions: Denied actions.
	NotActions []string `json:"notActions,omitempty"`

	// NotDataActions: Denied Data actions.
	NotDataActions []string `json:"notDataActions,omitempty"`
}

var _ genruntime.ARMTransformer = &Permission{}

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

	// Set property "Actions":
	for _, item := range permission.Actions {
		result.Actions = append(result.Actions, item)
	}

	// Set property "DataActions":
	for _, item := range permission.DataActions {
		result.DataActions = append(result.DataActions, item)
	}

	// Set property "NotActions":
	for _, item := range permission.NotActions {
		result.NotActions = append(result.NotActions, item)
	}

	// Set property "NotDataActions":
	for _, item := range permission.NotDataActions {
		result.NotDataActions = append(result.NotDataActions, item)
	}
	return result, nil
}

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

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

	// Set property "Actions":
	for _, item := range typedInput.Actions {
		permission.Actions = append(permission.Actions, item)
	}

	// Set property "DataActions":
	for _, item := range typedInput.DataActions {
		permission.DataActions = append(permission.DataActions, item)
	}

	// Set property "NotActions":
	for _, item := range typedInput.NotActions {
		permission.NotActions = append(permission.NotActions, item)
	}

	// Set property "NotDataActions":
	for _, item := range typedInput.NotDataActions {
		permission.NotDataActions = append(permission.NotDataActions, item)
	}

	// No error
	return nil
}

// AssignProperties_From_Permission populates our Permission from the provided source Permission
func (permission *Permission) AssignProperties_From_Permission(source *storage.Permission) error {

	// Actions
	permission.Actions = genruntime.CloneSliceOfString(source.Actions)

	// DataActions
	permission.DataActions = genruntime.CloneSliceOfString(source.DataActions)

	// NotActions
	permission.NotActions = genruntime.CloneSliceOfString(source.NotActions)

	// NotDataActions
	permission.NotDataActions = genruntime.CloneSliceOfString(source.NotDataActions)

	// No error
	return nil
}

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

	// Actions
	destination.Actions = genruntime.CloneSliceOfString(permission.Actions)

	// DataActions
	destination.DataActions = genruntime.CloneSliceOfString(permission.DataActions)

	// NotActions
	destination.NotActions = genruntime.CloneSliceOfString(permission.NotActions)

	// NotDataActions
	destination.NotDataActions = genruntime.CloneSliceOfString(permission.NotDataActions)

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

	// No error
	return nil
}

// Initialize_From_Permission_STATUS populates our Permission from the provided source Permission_STATUS
func (permission *Permission) Initialize_From_Permission_STATUS(source *Permission_STATUS) error {

	// Actions
	permission.Actions = genruntime.CloneSliceOfString(source.Actions)

	// DataActions
	permission.DataActions = genruntime.CloneSliceOfString(source.DataActions)

	// NotActions
	permission.NotActions = genruntime.CloneSliceOfString(source.NotActions)

	// NotDataActions
	permission.NotDataActions = genruntime.CloneSliceOfString(source.NotDataActions)

	// No error
	return nil
}

// Role definition permissions.
type Permission_STATUS struct {
	// Actions: Allowed actions.
	Actions []string `json:"actions,omitempty"`

	// DataActions: Allowed Data actions.
	DataActions []string `json:"dataActions,omitempty"`

	// NotActions: Denied actions.
	NotActions []string `json:"notActions,omitempty"`

	// NotDataActions: Denied Data actions.
	NotDataActions []string `json:"notDataActions,omitempty"`
}

var _ genruntime.FromARMConverter = &Permission_STATUS{}

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

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

	// Set property "Actions":
	for _, item := range typedInput.Actions {
		permission.Actions = append(permission.Actions, item)
	}

	// Set property "DataActions":
	for _, item := range typedInput.DataActions {
		permission.DataActions = append(permission.DataActions, item)
	}

	// Set property "NotActions":
	for _, item := range typedInput.NotActions {
		permission.NotActions = append(permission.NotActions, item)
	}

	// Set property "NotDataActions":
	for _, item := range typedInput.NotDataActions {
		permission.NotDataActions = append(permission.NotDataActions, item)
	}

	// No error
	return nil
}

// AssignProperties_From_Permission_STATUS populates our Permission_STATUS from the provided source Permission_STATUS
func (permission *Permission_STATUS) AssignProperties_From_Permission_STATUS(source *storage.Permission_STATUS) error {

	// Actions
	permission.Actions = genruntime.CloneSliceOfString(source.Actions)

	// DataActions
	permission.DataActions = genruntime.CloneSliceOfString(source.DataActions)

	// NotActions
	permission.NotActions = genruntime.CloneSliceOfString(source.NotActions)

	// NotDataActions
	permission.NotDataActions = genruntime.CloneSliceOfString(source.NotDataActions)

	// No error
	return nil
}

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

	// Actions
	destination.Actions = genruntime.CloneSliceOfString(permission.Actions)

	// DataActions
	destination.DataActions = genruntime.CloneSliceOfString(permission.DataActions)

	// NotActions
	destination.NotActions = genruntime.CloneSliceOfString(permission.NotActions)

	// NotDataActions
	destination.NotDataActions = genruntime.CloneSliceOfString(permission.NotDataActions)

	// 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 RoleDefinitionOperatorSpec struct {
	// ConfigMapExpressions: configures where to place operator written dynamic ConfigMaps (created with CEL expressions).
	ConfigMapExpressions []*core.DestinationExpression `json:"configMapExpressions,omitempty"`

	// NamingConvention: The uuid generation technique to use for any role without an explicit AzureName. One of 'stable' or
	// 'random'.
	// +kubebuilder:validation:Enum={"random","stable"}
	NamingConvention *string `json:"namingConvention,omitempty"`

	// SecretExpressions: configures where to place operator written dynamic secrets (created with CEL expressions).
	SecretExpressions []*core.DestinationExpression `json:"secretExpressions,omitempty"`
}

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

	// NamingConvention
	operator.NamingConvention = genruntime.ClonePointerToString(source.NamingConvention)

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

	// NamingConvention
	destination.NamingConvention = genruntime.ClonePointerToString(operator.NamingConvention)

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

func init() {
	SchemeBuilder.Register(&RoleDefinition{}, &RoleDefinitionList{})
}
