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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/kusto/v1api20240413/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/kusto/v1api20240413/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,kusto}
// +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: /azure-kusto/resource-manager/Microsoft.Kusto/Kusto/stable/2024-04-13/kusto.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/principalAssignments/{principalAssignmentName}
type PrincipalAssignment struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              PrincipalAssignment_Spec   `json:"spec,omitempty"`
	Status            PrincipalAssignment_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &PrincipalAssignment{}

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

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

var _ conversion.Convertible = &PrincipalAssignment{}

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

	return assignment.AssignProperties_From_PrincipalAssignment(source)
}

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

	return assignment.AssignProperties_To_PrincipalAssignment(destination)
}

var _ configmaps.Exporter = &PrincipalAssignment{}

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

var _ secrets.Exporter = &PrincipalAssignment{}

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

var _ genruntime.ImportableResource = &PrincipalAssignment{}

// InitializeSpec initializes the spec for this resource from the given status
func (assignment *PrincipalAssignment) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*PrincipalAssignment_STATUS); ok {
		return assignment.Spec.Initialize_From_PrincipalAssignment_STATUS(s)
	}

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

var _ genruntime.KubernetesResource = &PrincipalAssignment{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2024-04-13"
func (assignment PrincipalAssignment) GetAPIVersion() string {
	return "2024-04-13"
}

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.Kusto/clusters/databases/principalAssignments"
func (assignment *PrincipalAssignment) GetType() string {
	return "Microsoft.Kusto/clusters/databases/principalAssignments"
}

// NewEmptyStatus returns a new empty (blank) status
func (assignment *PrincipalAssignment) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &PrincipalAssignment_STATUS{}
}

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

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

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

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

	assignment.Status = st
	return nil
}

// AssignProperties_From_PrincipalAssignment populates our PrincipalAssignment from the provided source PrincipalAssignment
func (assignment *PrincipalAssignment) AssignProperties_From_PrincipalAssignment(source *storage.PrincipalAssignment) error {

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

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

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

	// No error
	return nil
}

// AssignProperties_To_PrincipalAssignment populates the provided destination PrincipalAssignment from our PrincipalAssignment
func (assignment *PrincipalAssignment) AssignProperties_To_PrincipalAssignment(destination *storage.PrincipalAssignment) error {

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

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

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

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /azure-kusto/resource-manager/Microsoft.Kusto/Kusto/stable/2024-04-13/kusto.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Kusto/clusters/{clusterName}/databases/{databaseName}/principalAssignments/{principalAssignmentName}
type PrincipalAssignmentList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []PrincipalAssignment `json:"items"`
}

type PrincipalAssignment_Spec struct {
	// +kubebuilder:validation:Pattern="^.*$"
	// 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"`

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

	// PrincipalId: The principal ID assigned to the database principal. It can be a user email, application ID, or security
	// group name.
	PrincipalId *string `json:"principalId,omitempty" optionalConfigMapPair:"PrincipalId"`

	// PrincipalIdFromConfig: The principal ID assigned to the database principal. It can be a user email, application ID, or
	// security group name.
	PrincipalIdFromConfig *genruntime.ConfigMapReference `json:"principalIdFromConfig,omitempty" optionalConfigMapPair:"PrincipalId"`

	// +kubebuilder:validation:Required
	// PrincipalType: Principal type.
	PrincipalType *DatabasePrincipalProperties_PrincipalType `json:"principalType,omitempty"`

	// +kubebuilder:validation:Required
	// Role: Database principal role.
	Role *DatabasePrincipalProperties_Role `json:"role,omitempty"`

	// TenantId: The tenant id of the principal
	TenantId *string `json:"tenantId,omitempty" optionalConfigMapPair:"TenantId"`

	// TenantIdFromConfig: The tenant id of the principal
	TenantIdFromConfig *genruntime.ConfigMapReference `json:"tenantIdFromConfig,omitempty" optionalConfigMapPair:"TenantId"`
}

var _ genruntime.ARMTransformer = &PrincipalAssignment_Spec{}

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

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

	// Set property "Properties":
	if assignment.PrincipalId != nil ||
		assignment.PrincipalIdFromConfig != nil ||
		assignment.PrincipalType != nil ||
		assignment.Role != nil ||
		assignment.TenantId != nil ||
		assignment.TenantIdFromConfig != nil {
		result.Properties = &arm.DatabasePrincipalProperties{}
	}
	if assignment.PrincipalId != nil {
		principalId := *assignment.PrincipalId
		result.Properties.PrincipalId = &principalId
	}
	if assignment.PrincipalIdFromConfig != nil {
		principalIdValue, err := resolved.ResolvedConfigMaps.Lookup(*assignment.PrincipalIdFromConfig)
		if err != nil {
			return nil, eris.Wrap(err, "looking up configmap for property PrincipalId")
		}
		principalId := principalIdValue
		result.Properties.PrincipalId = &principalId
	}
	if assignment.PrincipalType != nil {
		var temp string
		temp = string(*assignment.PrincipalType)
		principalType := arm.DatabasePrincipalProperties_PrincipalType(temp)
		result.Properties.PrincipalType = &principalType
	}
	if assignment.Role != nil {
		var temp string
		temp = string(*assignment.Role)
		role := arm.DatabasePrincipalProperties_Role(temp)
		result.Properties.Role = &role
	}
	if assignment.TenantId != nil {
		tenantId := *assignment.TenantId
		result.Properties.TenantId = &tenantId
	}
	if assignment.TenantIdFromConfig != nil {
		tenantIdValue, err := resolved.ResolvedConfigMaps.Lookup(*assignment.TenantIdFromConfig)
		if err != nil {
			return nil, eris.Wrap(err, "looking up configmap for property TenantId")
		}
		tenantId := tenantIdValue
		result.Properties.TenantId = &tenantId
	}
	return result, nil
}

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

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

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

	// no assignment for property "OperatorSpec"

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

	// Set property "PrincipalId":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.PrincipalId != nil {
			principalId := *typedInput.Properties.PrincipalId
			assignment.PrincipalId = &principalId
		}
	}

	// no assignment for property "PrincipalIdFromConfig"

	// Set property "PrincipalType":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.PrincipalType != nil {
			var temp string
			temp = string(*typedInput.Properties.PrincipalType)
			principalType := DatabasePrincipalProperties_PrincipalType(temp)
			assignment.PrincipalType = &principalType
		}
	}

	// Set property "Role":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Role != nil {
			var temp string
			temp = string(*typedInput.Properties.Role)
			role := DatabasePrincipalProperties_Role(temp)
			assignment.Role = &role
		}
	}

	// Set property "TenantId":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.TenantId != nil {
			tenantId := *typedInput.Properties.TenantId
			assignment.TenantId = &tenantId
		}
	}

	// no assignment for property "TenantIdFromConfig"

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &PrincipalAssignment_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.PrincipalAssignment_Spec{}
	err := assignment.AssignProperties_To_PrincipalAssignment_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_PrincipalAssignment_Spec populates our PrincipalAssignment_Spec from the provided source PrincipalAssignment_Spec
func (assignment *PrincipalAssignment_Spec) AssignProperties_From_PrincipalAssignment_Spec(source *storage.PrincipalAssignment_Spec) error {

	// AzureName
	assignment.AzureName = source.AzureName

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

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

	// PrincipalId
	assignment.PrincipalId = genruntime.ClonePointerToString(source.PrincipalId)

	// PrincipalIdFromConfig
	if source.PrincipalIdFromConfig != nil {
		principalIdFromConfig := source.PrincipalIdFromConfig.Copy()
		assignment.PrincipalIdFromConfig = &principalIdFromConfig
	} else {
		assignment.PrincipalIdFromConfig = nil
	}

	// PrincipalType
	if source.PrincipalType != nil {
		principalType := *source.PrincipalType
		principalTypeTemp := genruntime.ToEnum(principalType, databasePrincipalProperties_PrincipalType_Values)
		assignment.PrincipalType = &principalTypeTemp
	} else {
		assignment.PrincipalType = nil
	}

	// Role
	if source.Role != nil {
		role := *source.Role
		roleTemp := genruntime.ToEnum(role, databasePrincipalProperties_Role_Values)
		assignment.Role = &roleTemp
	} else {
		assignment.Role = nil
	}

	// TenantId
	assignment.TenantId = genruntime.ClonePointerToString(source.TenantId)

	// TenantIdFromConfig
	if source.TenantIdFromConfig != nil {
		tenantIdFromConfig := source.TenantIdFromConfig.Copy()
		assignment.TenantIdFromConfig = &tenantIdFromConfig
	} else {
		assignment.TenantIdFromConfig = nil
	}

	// No error
	return nil
}

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

	// AzureName
	destination.AzureName = assignment.AzureName

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

	// OriginalVersion
	destination.OriginalVersion = assignment.OriginalVersion()

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

	// PrincipalId
	destination.PrincipalId = genruntime.ClonePointerToString(assignment.PrincipalId)

	// PrincipalIdFromConfig
	if assignment.PrincipalIdFromConfig != nil {
		principalIdFromConfig := assignment.PrincipalIdFromConfig.Copy()
		destination.PrincipalIdFromConfig = &principalIdFromConfig
	} else {
		destination.PrincipalIdFromConfig = nil
	}

	// PrincipalType
	if assignment.PrincipalType != nil {
		principalType := string(*assignment.PrincipalType)
		destination.PrincipalType = &principalType
	} else {
		destination.PrincipalType = nil
	}

	// Role
	if assignment.Role != nil {
		role := string(*assignment.Role)
		destination.Role = &role
	} else {
		destination.Role = nil
	}

	// TenantId
	destination.TenantId = genruntime.ClonePointerToString(assignment.TenantId)

	// TenantIdFromConfig
	if assignment.TenantIdFromConfig != nil {
		tenantIdFromConfig := assignment.TenantIdFromConfig.Copy()
		destination.TenantIdFromConfig = &tenantIdFromConfig
	} else {
		destination.TenantIdFromConfig = nil
	}

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

	// No error
	return nil
}

// Initialize_From_PrincipalAssignment_STATUS populates our PrincipalAssignment_Spec from the provided source PrincipalAssignment_STATUS
func (assignment *PrincipalAssignment_Spec) Initialize_From_PrincipalAssignment_STATUS(source *PrincipalAssignment_STATUS) error {

	// PrincipalId
	assignment.PrincipalId = genruntime.ClonePointerToString(source.PrincipalId)

	// PrincipalType
	if source.PrincipalType != nil {
		principalType := genruntime.ToEnum(string(*source.PrincipalType), databasePrincipalProperties_PrincipalType_Values)
		assignment.PrincipalType = &principalType
	} else {
		assignment.PrincipalType = nil
	}

	// Role
	if source.Role != nil {
		role := genruntime.ToEnum(string(*source.Role), databasePrincipalProperties_Role_Values)
		assignment.Role = &role
	} else {
		assignment.Role = nil
	}

	// TenantId
	assignment.TenantId = genruntime.ClonePointerToString(source.TenantId)

	// No error
	return nil
}

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

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

type PrincipalAssignment_STATUS struct {
	// AadObjectId: The service principal object id in AAD (Azure active directory)
	AadObjectId *string `json:"aadObjectId,omitempty"`

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

	// Id: Fully qualified resource ID for the resource. Ex -
	// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}
	Id *string `json:"id,omitempty"`

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

	// PrincipalId: The principal ID assigned to the database principal. It can be a user email, application ID, or security
	// group name.
	PrincipalId *string `json:"principalId,omitempty"`

	// PrincipalName: The principal name
	PrincipalName *string `json:"principalName,omitempty"`

	// PrincipalType: Principal type.
	PrincipalType *DatabasePrincipalProperties_PrincipalType_STATUS `json:"principalType,omitempty"`

	// ProvisioningState: The provisioned state of the resource.
	ProvisioningState *ProvisioningState_STATUS `json:"provisioningState,omitempty"`

	// Role: Database principal role.
	Role *DatabasePrincipalProperties_Role_STATUS `json:"role,omitempty"`

	// TenantId: The tenant id of the principal
	TenantId *string `json:"tenantId,omitempty"`

	// TenantName: The tenant name of the principal
	TenantName *string `json:"tenantName,omitempty"`

	// Type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts"
	Type *string `json:"type,omitempty"`
}

var _ genruntime.ConvertibleStatus = &PrincipalAssignment_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.PrincipalAssignment_STATUS{}
	err := assignment.AssignProperties_To_PrincipalAssignment_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 = &PrincipalAssignment_STATUS{}

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

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

	// Set property "AadObjectId":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AadObjectId != nil {
			aadObjectId := *typedInput.Properties.AadObjectId
			assignment.AadObjectId = &aadObjectId
		}
	}

	// no assignment for property "Conditions"

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

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

	// Set property "PrincipalId":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.PrincipalId != nil {
			principalId := *typedInput.Properties.PrincipalId
			assignment.PrincipalId = &principalId
		}
	}

	// Set property "PrincipalName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.PrincipalName != nil {
			principalName := *typedInput.Properties.PrincipalName
			assignment.PrincipalName = &principalName
		}
	}

	// Set property "PrincipalType":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.PrincipalType != nil {
			var temp string
			temp = string(*typedInput.Properties.PrincipalType)
			principalType := DatabasePrincipalProperties_PrincipalType_STATUS(temp)
			assignment.PrincipalType = &principalType
		}
	}

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

	// Set property "Role":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Role != nil {
			var temp string
			temp = string(*typedInput.Properties.Role)
			role := DatabasePrincipalProperties_Role_STATUS(temp)
			assignment.Role = &role
		}
	}

	// Set property "TenantId":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.TenantId != nil {
			tenantId := *typedInput.Properties.TenantId
			assignment.TenantId = &tenantId
		}
	}

	// Set property "TenantName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.TenantName != nil {
			tenantName := *typedInput.Properties.TenantName
			assignment.TenantName = &tenantName
		}
	}

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

	// No error
	return nil
}

// AssignProperties_From_PrincipalAssignment_STATUS populates our PrincipalAssignment_STATUS from the provided source PrincipalAssignment_STATUS
func (assignment *PrincipalAssignment_STATUS) AssignProperties_From_PrincipalAssignment_STATUS(source *storage.PrincipalAssignment_STATUS) error {

	// AadObjectId
	assignment.AadObjectId = genruntime.ClonePointerToString(source.AadObjectId)

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

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

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

	// PrincipalId
	assignment.PrincipalId = genruntime.ClonePointerToString(source.PrincipalId)

	// PrincipalName
	assignment.PrincipalName = genruntime.ClonePointerToString(source.PrincipalName)

	// PrincipalType
	if source.PrincipalType != nil {
		principalType := *source.PrincipalType
		principalTypeTemp := genruntime.ToEnum(principalType, databasePrincipalProperties_PrincipalType_STATUS_Values)
		assignment.PrincipalType = &principalTypeTemp
	} else {
		assignment.PrincipalType = nil
	}

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

	// Role
	if source.Role != nil {
		role := *source.Role
		roleTemp := genruntime.ToEnum(role, databasePrincipalProperties_Role_STATUS_Values)
		assignment.Role = &roleTemp
	} else {
		assignment.Role = nil
	}

	// TenantId
	assignment.TenantId = genruntime.ClonePointerToString(source.TenantId)

	// TenantName
	assignment.TenantName = genruntime.ClonePointerToString(source.TenantName)

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

	// No error
	return nil
}

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

	// AadObjectId
	destination.AadObjectId = genruntime.ClonePointerToString(assignment.AadObjectId)

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

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

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

	// PrincipalId
	destination.PrincipalId = genruntime.ClonePointerToString(assignment.PrincipalId)

	// PrincipalName
	destination.PrincipalName = genruntime.ClonePointerToString(assignment.PrincipalName)

	// PrincipalType
	if assignment.PrincipalType != nil {
		principalType := string(*assignment.PrincipalType)
		destination.PrincipalType = &principalType
	} else {
		destination.PrincipalType = nil
	}

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

	// Role
	if assignment.Role != nil {
		role := string(*assignment.Role)
		destination.Role = &role
	} else {
		destination.Role = nil
	}

	// TenantId
	destination.TenantId = genruntime.ClonePointerToString(assignment.TenantId)

	// TenantName
	destination.TenantName = genruntime.ClonePointerToString(assignment.TenantName)

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

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

	// No error
	return nil
}

// +kubebuilder:validation:Enum={"App","Group","User"}
type DatabasePrincipalProperties_PrincipalType string

const (
	DatabasePrincipalProperties_PrincipalType_App   = DatabasePrincipalProperties_PrincipalType("App")
	DatabasePrincipalProperties_PrincipalType_Group = DatabasePrincipalProperties_PrincipalType("Group")
	DatabasePrincipalProperties_PrincipalType_User  = DatabasePrincipalProperties_PrincipalType("User")
)

// Mapping from string to DatabasePrincipalProperties_PrincipalType
var databasePrincipalProperties_PrincipalType_Values = map[string]DatabasePrincipalProperties_PrincipalType{
	"app":   DatabasePrincipalProperties_PrincipalType_App,
	"group": DatabasePrincipalProperties_PrincipalType_Group,
	"user":  DatabasePrincipalProperties_PrincipalType_User,
}

type DatabasePrincipalProperties_PrincipalType_STATUS string

const (
	DatabasePrincipalProperties_PrincipalType_STATUS_App   = DatabasePrincipalProperties_PrincipalType_STATUS("App")
	DatabasePrincipalProperties_PrincipalType_STATUS_Group = DatabasePrincipalProperties_PrincipalType_STATUS("Group")
	DatabasePrincipalProperties_PrincipalType_STATUS_User  = DatabasePrincipalProperties_PrincipalType_STATUS("User")
)

// Mapping from string to DatabasePrincipalProperties_PrincipalType_STATUS
var databasePrincipalProperties_PrincipalType_STATUS_Values = map[string]DatabasePrincipalProperties_PrincipalType_STATUS{
	"app":   DatabasePrincipalProperties_PrincipalType_STATUS_App,
	"group": DatabasePrincipalProperties_PrincipalType_STATUS_Group,
	"user":  DatabasePrincipalProperties_PrincipalType_STATUS_User,
}

// +kubebuilder:validation:Enum={"Admin","Ingestor","Monitor","UnrestrictedViewer","User","Viewer"}
type DatabasePrincipalProperties_Role string

const (
	DatabasePrincipalProperties_Role_Admin              = DatabasePrincipalProperties_Role("Admin")
	DatabasePrincipalProperties_Role_Ingestor           = DatabasePrincipalProperties_Role("Ingestor")
	DatabasePrincipalProperties_Role_Monitor            = DatabasePrincipalProperties_Role("Monitor")
	DatabasePrincipalProperties_Role_UnrestrictedViewer = DatabasePrincipalProperties_Role("UnrestrictedViewer")
	DatabasePrincipalProperties_Role_User               = DatabasePrincipalProperties_Role("User")
	DatabasePrincipalProperties_Role_Viewer             = DatabasePrincipalProperties_Role("Viewer")
)

// Mapping from string to DatabasePrincipalProperties_Role
var databasePrincipalProperties_Role_Values = map[string]DatabasePrincipalProperties_Role{
	"admin":              DatabasePrincipalProperties_Role_Admin,
	"ingestor":           DatabasePrincipalProperties_Role_Ingestor,
	"monitor":            DatabasePrincipalProperties_Role_Monitor,
	"unrestrictedviewer": DatabasePrincipalProperties_Role_UnrestrictedViewer,
	"user":               DatabasePrincipalProperties_Role_User,
	"viewer":             DatabasePrincipalProperties_Role_Viewer,
}

type DatabasePrincipalProperties_Role_STATUS string

const (
	DatabasePrincipalProperties_Role_STATUS_Admin              = DatabasePrincipalProperties_Role_STATUS("Admin")
	DatabasePrincipalProperties_Role_STATUS_Ingestor           = DatabasePrincipalProperties_Role_STATUS("Ingestor")
	DatabasePrincipalProperties_Role_STATUS_Monitor            = DatabasePrincipalProperties_Role_STATUS("Monitor")
	DatabasePrincipalProperties_Role_STATUS_UnrestrictedViewer = DatabasePrincipalProperties_Role_STATUS("UnrestrictedViewer")
	DatabasePrincipalProperties_Role_STATUS_User               = DatabasePrincipalProperties_Role_STATUS("User")
	DatabasePrincipalProperties_Role_STATUS_Viewer             = DatabasePrincipalProperties_Role_STATUS("Viewer")
)

// Mapping from string to DatabasePrincipalProperties_Role_STATUS
var databasePrincipalProperties_Role_STATUS_Values = map[string]DatabasePrincipalProperties_Role_STATUS{
	"admin":              DatabasePrincipalProperties_Role_STATUS_Admin,
	"ingestor":           DatabasePrincipalProperties_Role_STATUS_Ingestor,
	"monitor":            DatabasePrincipalProperties_Role_STATUS_Monitor,
	"unrestrictedviewer": DatabasePrincipalProperties_Role_STATUS_UnrestrictedViewer,
	"user":               DatabasePrincipalProperties_Role_STATUS_User,
	"viewer":             DatabasePrincipalProperties_Role_STATUS_Viewer,
}

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

func init() {
	SchemeBuilder.Register(&PrincipalAssignment{}, &PrincipalAssignmentList{})
}
