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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/sql/v1api20211101/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/sql/v1api20211101/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,sql}
// +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: /sql/resource-manager/Microsoft.Sql/stable/2021-11-01/BlobAuditing.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/default
type ServersDatabasesAuditingSetting struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              ServersDatabasesAuditingSetting_Spec   `json:"spec,omitempty"`
	Status            ServersDatabasesAuditingSetting_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &ServersDatabasesAuditingSetting{}

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

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

var _ conversion.Convertible = &ServersDatabasesAuditingSetting{}

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

	return setting.AssignProperties_From_ServersDatabasesAuditingSetting(source)
}

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

	return setting.AssignProperties_To_ServersDatabasesAuditingSetting(destination)
}

var _ configmaps.Exporter = &ServersDatabasesAuditingSetting{}

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

var _ secrets.Exporter = &ServersDatabasesAuditingSetting{}

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

var _ genruntime.ImportableResource = &ServersDatabasesAuditingSetting{}

// InitializeSpec initializes the spec for this resource from the given status
func (setting *ServersDatabasesAuditingSetting) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*ServersDatabasesAuditingSetting_STATUS); ok {
		return setting.Spec.Initialize_From_ServersDatabasesAuditingSetting_STATUS(s)
	}

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

var _ genruntime.KubernetesResource = &ServersDatabasesAuditingSetting{}

// AzureName returns the Azure name of the resource (always "default")
func (setting *ServersDatabasesAuditingSetting) AzureName() string {
	return "default"
}

// GetAPIVersion returns the ARM API version of the resource. This is always "2021-11-01"
func (setting ServersDatabasesAuditingSetting) GetAPIVersion() string {
	return "2021-11-01"
}

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.Sql/servers/databases/auditingSettings"
func (setting *ServersDatabasesAuditingSetting) GetType() string {
	return "Microsoft.Sql/servers/databases/auditingSettings"
}

// NewEmptyStatus returns a new empty (blank) status
func (setting *ServersDatabasesAuditingSetting) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &ServersDatabasesAuditingSetting_STATUS{}
}

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

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

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

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

	setting.Status = st
	return nil
}

// AssignProperties_From_ServersDatabasesAuditingSetting populates our ServersDatabasesAuditingSetting from the provided source ServersDatabasesAuditingSetting
func (setting *ServersDatabasesAuditingSetting) AssignProperties_From_ServersDatabasesAuditingSetting(source *storage.ServersDatabasesAuditingSetting) error {

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

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

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

	// No error
	return nil
}

// AssignProperties_To_ServersDatabasesAuditingSetting populates the provided destination ServersDatabasesAuditingSetting from our ServersDatabasesAuditingSetting
func (setting *ServersDatabasesAuditingSetting) AssignProperties_To_ServersDatabasesAuditingSetting(destination *storage.ServersDatabasesAuditingSetting) error {

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

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

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

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /sql/resource-manager/Microsoft.Sql/stable/2021-11-01/BlobAuditing.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/default
type ServersDatabasesAuditingSettingList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []ServersDatabasesAuditingSetting `json:"items"`
}

type ServersDatabasesAuditingSetting_Spec struct {
	// AuditActionsAndGroups: Specifies the Actions-Groups and Actions to audit.
	// The recommended set of action groups to use is the following combination - this will audit all the queries and stored
	// procedures executed against the database, as well as successful and failed logins:
	// BATCH_COMPLETED_GROUP,
	// SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP,
	// FAILED_DATABASE_AUTHENTICATION_GROUP.
	// This above combination is also the set that is configured by default when enabling auditing from the Azure portal.
	// The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using
	// unnecessary groups could lead to very large quantities of audit records):
	// APPLICATION_ROLE_CHANGE_PASSWORD_GROUP
	// BACKUP_RESTORE_GROUP
	// DATABASE_LOGOUT_GROUP
	// DATABASE_OBJECT_CHANGE_GROUP
	// DATABASE_OBJECT_OWNERSHIP_CHANGE_GROUP
	// DATABASE_OBJECT_PERMISSION_CHANGE_GROUP
	// DATABASE_OPERATION_GROUP
	// DATABASE_PERMISSION_CHANGE_GROUP
	// DATABASE_PRINCIPAL_CHANGE_GROUP
	// DATABASE_PRINCIPAL_IMPERSONATION_GROUP
	// DATABASE_ROLE_MEMBER_CHANGE_GROUP
	// FAILED_DATABASE_AUTHENTICATION_GROUP
	// SCHEMA_OBJECT_ACCESS_GROUP
	// SCHEMA_OBJECT_CHANGE_GROUP
	// SCHEMA_OBJECT_OWNERSHIP_CHANGE_GROUP
	// SCHEMA_OBJECT_PERMISSION_CHANGE_GROUP
	// SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP
	// USER_CHANGE_PASSWORD_GROUP
	// BATCH_STARTED_GROUP
	// BATCH_COMPLETED_GROUP
	// DBCC_GROUP
	// DATABASE_OWNERSHIP_CHANGE_GROUP
	// DATABASE_CHANGE_GROUP
	// LEDGER_OPERATION_GROUP
	// These are groups that cover all sql statements and stored procedures executed against the database, and should not be
	// used in combination with other groups as this will result in duplicate audit logs.
	// For more information, see [Database-Level Audit Action
	// Groups](https://docs.microsoft.com/en-us/sql/relational-databases/security/auditing/sql-server-audit-action-groups-and-actions#database-level-audit-action-groups).
	// For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server
	// auditing policy). The supported actions to audit are:
	// SELECT
	// UPDATE
	// INSERT
	// DELETE
	// EXECUTE
	// RECEIVE
	// REFERENCES
	// The general form for defining an action to be audited is:
	// {action} ON {object} BY {principal}
	// Note that <object> in the above format can refer to an object like a table, view, or stored procedure, or an entire
	// database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively.
	// For example:
	// SELECT on dbo.myTable by public
	// SELECT on DATABASE::myDatabase by public
	// SELECT on SCHEMA::mySchema by public
	// For more information, see [Database-Level Audit
	// Actions](https://docs.microsoft.com/en-us/sql/relational-databases/security/auditing/sql-server-audit-action-groups-and-actions#database-level-audit-actions)
	AuditActionsAndGroups []string `json:"auditActionsAndGroups,omitempty"`

	// IsAzureMonitorTargetEnabled: Specifies whether audit events are sent to Azure Monitor.
	// In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true.
	// When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on
	// the database should be also created.
	// Note that for server level audit you should use the 'master' database as {databaseName}.
	// Diagnostic Settings URI format:
	// PUT
	// https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview
	// For more information, see [Diagnostic Settings REST API](https://go.microsoft.com/fwlink/?linkid=2033207)
	// or [Diagnostic Settings PowerShell](https://go.microsoft.com/fwlink/?linkid=2033043)
	IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"`

	// IsManagedIdentityInUse: Specifies whether Managed Identity is used to access blob storage
	IsManagedIdentityInUse *bool `json:"isManagedIdentityInUse,omitempty"`

	// IsStorageSecondaryKeyInUse: Specifies whether storageAccountAccessKey value is the storage's secondary key.
	IsStorageSecondaryKeyInUse *bool `json:"isStorageSecondaryKeyInUse,omitempty"`

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

	// QueueDelayMs: Specifies the amount of time in milliseconds that can elapse before audit actions are forced to be
	// processed.
	// The default minimum value is 1000 (1 second). The maximum is 2,147,483,647.
	QueueDelayMs *int `json:"queueDelayMs,omitempty"`

	// RetentionDays: Specifies the number of days to keep in the audit logs in the storage account.
	RetentionDays *int `json:"retentionDays,omitempty"`

	// +kubebuilder:validation:Required
	// State: Specifies the state of the audit. If state is Enabled, storageEndpoint or isAzureMonitorTargetEnabled are
	// required.
	State *DatabaseBlobAuditingPolicyProperties_State `json:"state,omitempty"`

	// StorageAccountAccessKey: Specifies the identifier key of the auditing storage account.
	// If state is Enabled and storageEndpoint is specified, not specifying the storageAccountAccessKey will use SQL server
	// system-assigned managed identity to access the storage.
	// Prerequisites for using managed identity authentication:
	// 1. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD).
	// 2. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the
	// server identity.
	// For more information, see [Auditing to storage using Managed Identity
	// authentication](https://go.microsoft.com/fwlink/?linkid=2114355)
	StorageAccountAccessKey *genruntime.SecretReference `json:"storageAccountAccessKey,omitempty"`

	// +kubebuilder:validation:Pattern="^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
	// StorageAccountSubscriptionId: Specifies the blob storage subscription Id.
	StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"`

	// StorageEndpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is
	// Enabled, storageEndpoint or isAzureMonitorTargetEnabled is required.
	StorageEndpoint *string `json:"storageEndpoint,omitempty"`
}

var _ genruntime.ARMTransformer = &ServersDatabasesAuditingSetting_Spec{}

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

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

	// Set property "Properties":
	if setting.AuditActionsAndGroups != nil ||
		setting.IsAzureMonitorTargetEnabled != nil ||
		setting.IsManagedIdentityInUse != nil ||
		setting.IsStorageSecondaryKeyInUse != nil ||
		setting.QueueDelayMs != nil ||
		setting.RetentionDays != nil ||
		setting.State != nil ||
		setting.StorageAccountAccessKey != nil ||
		setting.StorageAccountSubscriptionId != nil ||
		setting.StorageEndpoint != nil {
		result.Properties = &arm.DatabaseBlobAuditingPolicyProperties{}
	}
	for _, item := range setting.AuditActionsAndGroups {
		result.Properties.AuditActionsAndGroups = append(result.Properties.AuditActionsAndGroups, item)
	}
	if setting.IsAzureMonitorTargetEnabled != nil {
		isAzureMonitorTargetEnabled := *setting.IsAzureMonitorTargetEnabled
		result.Properties.IsAzureMonitorTargetEnabled = &isAzureMonitorTargetEnabled
	}
	if setting.IsManagedIdentityInUse != nil {
		isManagedIdentityInUse := *setting.IsManagedIdentityInUse
		result.Properties.IsManagedIdentityInUse = &isManagedIdentityInUse
	}
	if setting.IsStorageSecondaryKeyInUse != nil {
		isStorageSecondaryKeyInUse := *setting.IsStorageSecondaryKeyInUse
		result.Properties.IsStorageSecondaryKeyInUse = &isStorageSecondaryKeyInUse
	}
	if setting.QueueDelayMs != nil {
		queueDelayMs := *setting.QueueDelayMs
		result.Properties.QueueDelayMs = &queueDelayMs
	}
	if setting.RetentionDays != nil {
		retentionDays := *setting.RetentionDays
		result.Properties.RetentionDays = &retentionDays
	}
	if setting.State != nil {
		var temp string
		temp = string(*setting.State)
		state := arm.DatabaseBlobAuditingPolicyProperties_State(temp)
		result.Properties.State = &state
	}
	if setting.StorageAccountAccessKey != nil {
		storageAccountAccessKeySecret, err := resolved.ResolvedSecrets.Lookup(*setting.StorageAccountAccessKey)
		if err != nil {
			return nil, eris.Wrap(err, "looking up secret for property StorageAccountAccessKey")
		}
		storageAccountAccessKey := storageAccountAccessKeySecret
		result.Properties.StorageAccountAccessKey = &storageAccountAccessKey
	}
	if setting.StorageAccountSubscriptionId != nil {
		storageAccountSubscriptionId := *setting.StorageAccountSubscriptionId
		result.Properties.StorageAccountSubscriptionId = &storageAccountSubscriptionId
	}
	if setting.StorageEndpoint != nil {
		storageEndpoint := *setting.StorageEndpoint
		result.Properties.StorageEndpoint = &storageEndpoint
	}
	return result, nil
}

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

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

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

	// Set property "IsAzureMonitorTargetEnabled":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.IsAzureMonitorTargetEnabled != nil {
			isAzureMonitorTargetEnabled := *typedInput.Properties.IsAzureMonitorTargetEnabled
			setting.IsAzureMonitorTargetEnabled = &isAzureMonitorTargetEnabled
		}
	}

	// Set property "IsManagedIdentityInUse":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.IsManagedIdentityInUse != nil {
			isManagedIdentityInUse := *typedInput.Properties.IsManagedIdentityInUse
			setting.IsManagedIdentityInUse = &isManagedIdentityInUse
		}
	}

	// Set property "IsStorageSecondaryKeyInUse":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.IsStorageSecondaryKeyInUse != nil {
			isStorageSecondaryKeyInUse := *typedInput.Properties.IsStorageSecondaryKeyInUse
			setting.IsStorageSecondaryKeyInUse = &isStorageSecondaryKeyInUse
		}
	}

	// no assignment for property "OperatorSpec"

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

	// Set property "QueueDelayMs":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.QueueDelayMs != nil {
			queueDelayMs := *typedInput.Properties.QueueDelayMs
			setting.QueueDelayMs = &queueDelayMs
		}
	}

	// Set property "RetentionDays":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RetentionDays != nil {
			retentionDays := *typedInput.Properties.RetentionDays
			setting.RetentionDays = &retentionDays
		}
	}

	// Set property "State":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.State != nil {
			var temp string
			temp = string(*typedInput.Properties.State)
			state := DatabaseBlobAuditingPolicyProperties_State(temp)
			setting.State = &state
		}
	}

	// no assignment for property "StorageAccountAccessKey"

	// Set property "StorageAccountSubscriptionId":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.StorageAccountSubscriptionId != nil {
			storageAccountSubscriptionId := *typedInput.Properties.StorageAccountSubscriptionId
			setting.StorageAccountSubscriptionId = &storageAccountSubscriptionId
		}
	}

	// Set property "StorageEndpoint":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.StorageEndpoint != nil {
			storageEndpoint := *typedInput.Properties.StorageEndpoint
			setting.StorageEndpoint = &storageEndpoint
		}
	}

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &ServersDatabasesAuditingSetting_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.ServersDatabasesAuditingSetting_Spec{}
	err := setting.AssignProperties_To_ServersDatabasesAuditingSetting_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_ServersDatabasesAuditingSetting_Spec populates our ServersDatabasesAuditingSetting_Spec from the provided source ServersDatabasesAuditingSetting_Spec
func (setting *ServersDatabasesAuditingSetting_Spec) AssignProperties_From_ServersDatabasesAuditingSetting_Spec(source *storage.ServersDatabasesAuditingSetting_Spec) error {

	// AuditActionsAndGroups
	setting.AuditActionsAndGroups = genruntime.CloneSliceOfString(source.AuditActionsAndGroups)

	// IsAzureMonitorTargetEnabled
	if source.IsAzureMonitorTargetEnabled != nil {
		isAzureMonitorTargetEnabled := *source.IsAzureMonitorTargetEnabled
		setting.IsAzureMonitorTargetEnabled = &isAzureMonitorTargetEnabled
	} else {
		setting.IsAzureMonitorTargetEnabled = nil
	}

	// IsManagedIdentityInUse
	if source.IsManagedIdentityInUse != nil {
		isManagedIdentityInUse := *source.IsManagedIdentityInUse
		setting.IsManagedIdentityInUse = &isManagedIdentityInUse
	} else {
		setting.IsManagedIdentityInUse = nil
	}

	// IsStorageSecondaryKeyInUse
	if source.IsStorageSecondaryKeyInUse != nil {
		isStorageSecondaryKeyInUse := *source.IsStorageSecondaryKeyInUse
		setting.IsStorageSecondaryKeyInUse = &isStorageSecondaryKeyInUse
	} else {
		setting.IsStorageSecondaryKeyInUse = nil
	}

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

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

	// QueueDelayMs
	setting.QueueDelayMs = genruntime.ClonePointerToInt(source.QueueDelayMs)

	// RetentionDays
	setting.RetentionDays = genruntime.ClonePointerToInt(source.RetentionDays)

	// State
	if source.State != nil {
		state := *source.State
		stateTemp := genruntime.ToEnum(state, databaseBlobAuditingPolicyProperties_State_Values)
		setting.State = &stateTemp
	} else {
		setting.State = nil
	}

	// StorageAccountAccessKey
	if source.StorageAccountAccessKey != nil {
		storageAccountAccessKey := source.StorageAccountAccessKey.Copy()
		setting.StorageAccountAccessKey = &storageAccountAccessKey
	} else {
		setting.StorageAccountAccessKey = nil
	}

	// StorageAccountSubscriptionId
	setting.StorageAccountSubscriptionId = genruntime.ClonePointerToString(source.StorageAccountSubscriptionId)

	// StorageEndpoint
	setting.StorageEndpoint = genruntime.ClonePointerToString(source.StorageEndpoint)

	// No error
	return nil
}

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

	// AuditActionsAndGroups
	destination.AuditActionsAndGroups = genruntime.CloneSliceOfString(setting.AuditActionsAndGroups)

	// IsAzureMonitorTargetEnabled
	if setting.IsAzureMonitorTargetEnabled != nil {
		isAzureMonitorTargetEnabled := *setting.IsAzureMonitorTargetEnabled
		destination.IsAzureMonitorTargetEnabled = &isAzureMonitorTargetEnabled
	} else {
		destination.IsAzureMonitorTargetEnabled = nil
	}

	// IsManagedIdentityInUse
	if setting.IsManagedIdentityInUse != nil {
		isManagedIdentityInUse := *setting.IsManagedIdentityInUse
		destination.IsManagedIdentityInUse = &isManagedIdentityInUse
	} else {
		destination.IsManagedIdentityInUse = nil
	}

	// IsStorageSecondaryKeyInUse
	if setting.IsStorageSecondaryKeyInUse != nil {
		isStorageSecondaryKeyInUse := *setting.IsStorageSecondaryKeyInUse
		destination.IsStorageSecondaryKeyInUse = &isStorageSecondaryKeyInUse
	} else {
		destination.IsStorageSecondaryKeyInUse = nil
	}

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

	// OriginalVersion
	destination.OriginalVersion = setting.OriginalVersion()

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

	// QueueDelayMs
	destination.QueueDelayMs = genruntime.ClonePointerToInt(setting.QueueDelayMs)

	// RetentionDays
	destination.RetentionDays = genruntime.ClonePointerToInt(setting.RetentionDays)

	// State
	if setting.State != nil {
		state := string(*setting.State)
		destination.State = &state
	} else {
		destination.State = nil
	}

	// StorageAccountAccessKey
	if setting.StorageAccountAccessKey != nil {
		storageAccountAccessKey := setting.StorageAccountAccessKey.Copy()
		destination.StorageAccountAccessKey = &storageAccountAccessKey
	} else {
		destination.StorageAccountAccessKey = nil
	}

	// StorageAccountSubscriptionId
	destination.StorageAccountSubscriptionId = genruntime.ClonePointerToString(setting.StorageAccountSubscriptionId)

	// StorageEndpoint
	destination.StorageEndpoint = genruntime.ClonePointerToString(setting.StorageEndpoint)

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

	// No error
	return nil
}

// Initialize_From_ServersDatabasesAuditingSetting_STATUS populates our ServersDatabasesAuditingSetting_Spec from the provided source ServersDatabasesAuditingSetting_STATUS
func (setting *ServersDatabasesAuditingSetting_Spec) Initialize_From_ServersDatabasesAuditingSetting_STATUS(source *ServersDatabasesAuditingSetting_STATUS) error {

	// AuditActionsAndGroups
	setting.AuditActionsAndGroups = genruntime.CloneSliceOfString(source.AuditActionsAndGroups)

	// IsAzureMonitorTargetEnabled
	if source.IsAzureMonitorTargetEnabled != nil {
		isAzureMonitorTargetEnabled := *source.IsAzureMonitorTargetEnabled
		setting.IsAzureMonitorTargetEnabled = &isAzureMonitorTargetEnabled
	} else {
		setting.IsAzureMonitorTargetEnabled = nil
	}

	// IsManagedIdentityInUse
	if source.IsManagedIdentityInUse != nil {
		isManagedIdentityInUse := *source.IsManagedIdentityInUse
		setting.IsManagedIdentityInUse = &isManagedIdentityInUse
	} else {
		setting.IsManagedIdentityInUse = nil
	}

	// IsStorageSecondaryKeyInUse
	if source.IsStorageSecondaryKeyInUse != nil {
		isStorageSecondaryKeyInUse := *source.IsStorageSecondaryKeyInUse
		setting.IsStorageSecondaryKeyInUse = &isStorageSecondaryKeyInUse
	} else {
		setting.IsStorageSecondaryKeyInUse = nil
	}

	// QueueDelayMs
	setting.QueueDelayMs = genruntime.ClonePointerToInt(source.QueueDelayMs)

	// RetentionDays
	setting.RetentionDays = genruntime.ClonePointerToInt(source.RetentionDays)

	// State
	if source.State != nil {
		state := genruntime.ToEnum(string(*source.State), databaseBlobAuditingPolicyProperties_State_Values)
		setting.State = &state
	} else {
		setting.State = nil
	}

	// StorageAccountSubscriptionId
	setting.StorageAccountSubscriptionId = genruntime.ClonePointerToString(source.StorageAccountSubscriptionId)

	// StorageEndpoint
	setting.StorageEndpoint = genruntime.ClonePointerToString(source.StorageEndpoint)

	// No error
	return nil
}

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

type ServersDatabasesAuditingSetting_STATUS struct {
	// AuditActionsAndGroups: Specifies the Actions-Groups and Actions to audit.
	// The recommended set of action groups to use is the following combination - this will audit all the queries and stored
	// procedures executed against the database, as well as successful and failed logins:
	// BATCH_COMPLETED_GROUP,
	// SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP,
	// FAILED_DATABASE_AUTHENTICATION_GROUP.
	// This above combination is also the set that is configured by default when enabling auditing from the Azure portal.
	// The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using
	// unnecessary groups could lead to very large quantities of audit records):
	// APPLICATION_ROLE_CHANGE_PASSWORD_GROUP
	// BACKUP_RESTORE_GROUP
	// DATABASE_LOGOUT_GROUP
	// DATABASE_OBJECT_CHANGE_GROUP
	// DATABASE_OBJECT_OWNERSHIP_CHANGE_GROUP
	// DATABASE_OBJECT_PERMISSION_CHANGE_GROUP
	// DATABASE_OPERATION_GROUP
	// DATABASE_PERMISSION_CHANGE_GROUP
	// DATABASE_PRINCIPAL_CHANGE_GROUP
	// DATABASE_PRINCIPAL_IMPERSONATION_GROUP
	// DATABASE_ROLE_MEMBER_CHANGE_GROUP
	// FAILED_DATABASE_AUTHENTICATION_GROUP
	// SCHEMA_OBJECT_ACCESS_GROUP
	// SCHEMA_OBJECT_CHANGE_GROUP
	// SCHEMA_OBJECT_OWNERSHIP_CHANGE_GROUP
	// SCHEMA_OBJECT_PERMISSION_CHANGE_GROUP
	// SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP
	// USER_CHANGE_PASSWORD_GROUP
	// BATCH_STARTED_GROUP
	// BATCH_COMPLETED_GROUP
	// DBCC_GROUP
	// DATABASE_OWNERSHIP_CHANGE_GROUP
	// DATABASE_CHANGE_GROUP
	// LEDGER_OPERATION_GROUP
	// These are groups that cover all sql statements and stored procedures executed against the database, and should not be
	// used in combination with other groups as this will result in duplicate audit logs.
	// For more information, see [Database-Level Audit Action
	// Groups](https://docs.microsoft.com/en-us/sql/relational-databases/security/auditing/sql-server-audit-action-groups-and-actions#database-level-audit-action-groups).
	// For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server
	// auditing policy). The supported actions to audit are:
	// SELECT
	// UPDATE
	// INSERT
	// DELETE
	// EXECUTE
	// RECEIVE
	// REFERENCES
	// The general form for defining an action to be audited is:
	// {action} ON {object} BY {principal}
	// Note that <object> in the above format can refer to an object like a table, view, or stored procedure, or an entire
	// database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively.
	// For example:
	// SELECT on dbo.myTable by public
	// SELECT on DATABASE::myDatabase by public
	// SELECT on SCHEMA::mySchema by public
	// For more information, see [Database-Level Audit
	// Actions](https://docs.microsoft.com/en-us/sql/relational-databases/security/auditing/sql-server-audit-action-groups-and-actions#database-level-audit-actions)
	AuditActionsAndGroups []string `json:"auditActionsAndGroups,omitempty"`

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

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

	// IsAzureMonitorTargetEnabled: Specifies whether audit events are sent to Azure Monitor.
	// In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true.
	// When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on
	// the database should be also created.
	// Note that for server level audit you should use the 'master' database as {databaseName}.
	// Diagnostic Settings URI format:
	// PUT
	// https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview
	// For more information, see [Diagnostic Settings REST API](https://go.microsoft.com/fwlink/?linkid=2033207)
	// or [Diagnostic Settings PowerShell](https://go.microsoft.com/fwlink/?linkid=2033043)
	IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"`

	// IsManagedIdentityInUse: Specifies whether Managed Identity is used to access blob storage
	IsManagedIdentityInUse *bool `json:"isManagedIdentityInUse,omitempty"`

	// IsStorageSecondaryKeyInUse: Specifies whether storageAccountAccessKey value is the storage's secondary key.
	IsStorageSecondaryKeyInUse *bool `json:"isStorageSecondaryKeyInUse,omitempty"`

	// Kind: Resource kind.
	Kind *string `json:"kind,omitempty"`

	// Name: Resource name.
	Name *string `json:"name,omitempty"`

	// QueueDelayMs: Specifies the amount of time in milliseconds that can elapse before audit actions are forced to be
	// processed.
	// The default minimum value is 1000 (1 second). The maximum is 2,147,483,647.
	QueueDelayMs *int `json:"queueDelayMs,omitempty"`

	// RetentionDays: Specifies the number of days to keep in the audit logs in the storage account.
	RetentionDays *int `json:"retentionDays,omitempty"`

	// State: Specifies the state of the audit. If state is Enabled, storageEndpoint or isAzureMonitorTargetEnabled are
	// required.
	State *DatabaseBlobAuditingPolicyProperties_State_STATUS `json:"state,omitempty"`

	// StorageAccountSubscriptionId: Specifies the blob storage subscription Id.
	StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"`

	// StorageEndpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is
	// Enabled, storageEndpoint or isAzureMonitorTargetEnabled is required.
	StorageEndpoint *string `json:"storageEndpoint,omitempty"`

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

var _ genruntime.ConvertibleStatus = &ServersDatabasesAuditingSetting_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.ServersDatabasesAuditingSetting_STATUS{}
	err := setting.AssignProperties_To_ServersDatabasesAuditingSetting_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 = &ServersDatabasesAuditingSetting_STATUS{}

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

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

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

	// no assignment for property "Conditions"

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

	// Set property "IsAzureMonitorTargetEnabled":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.IsAzureMonitorTargetEnabled != nil {
			isAzureMonitorTargetEnabled := *typedInput.Properties.IsAzureMonitorTargetEnabled
			setting.IsAzureMonitorTargetEnabled = &isAzureMonitorTargetEnabled
		}
	}

	// Set property "IsManagedIdentityInUse":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.IsManagedIdentityInUse != nil {
			isManagedIdentityInUse := *typedInput.Properties.IsManagedIdentityInUse
			setting.IsManagedIdentityInUse = &isManagedIdentityInUse
		}
	}

	// Set property "IsStorageSecondaryKeyInUse":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.IsStorageSecondaryKeyInUse != nil {
			isStorageSecondaryKeyInUse := *typedInput.Properties.IsStorageSecondaryKeyInUse
			setting.IsStorageSecondaryKeyInUse = &isStorageSecondaryKeyInUse
		}
	}

	// Set property "Kind":
	if typedInput.Kind != nil {
		kind := *typedInput.Kind
		setting.Kind = &kind
	}

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

	// Set property "QueueDelayMs":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.QueueDelayMs != nil {
			queueDelayMs := *typedInput.Properties.QueueDelayMs
			setting.QueueDelayMs = &queueDelayMs
		}
	}

	// Set property "RetentionDays":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.RetentionDays != nil {
			retentionDays := *typedInput.Properties.RetentionDays
			setting.RetentionDays = &retentionDays
		}
	}

	// Set property "State":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.State != nil {
			var temp string
			temp = string(*typedInput.Properties.State)
			state := DatabaseBlobAuditingPolicyProperties_State_STATUS(temp)
			setting.State = &state
		}
	}

	// Set property "StorageAccountSubscriptionId":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.StorageAccountSubscriptionId != nil {
			storageAccountSubscriptionId := *typedInput.Properties.StorageAccountSubscriptionId
			setting.StorageAccountSubscriptionId = &storageAccountSubscriptionId
		}
	}

	// Set property "StorageEndpoint":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.StorageEndpoint != nil {
			storageEndpoint := *typedInput.Properties.StorageEndpoint
			setting.StorageEndpoint = &storageEndpoint
		}
	}

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

	// No error
	return nil
}

// AssignProperties_From_ServersDatabasesAuditingSetting_STATUS populates our ServersDatabasesAuditingSetting_STATUS from the provided source ServersDatabasesAuditingSetting_STATUS
func (setting *ServersDatabasesAuditingSetting_STATUS) AssignProperties_From_ServersDatabasesAuditingSetting_STATUS(source *storage.ServersDatabasesAuditingSetting_STATUS) error {

	// AuditActionsAndGroups
	setting.AuditActionsAndGroups = genruntime.CloneSliceOfString(source.AuditActionsAndGroups)

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

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

	// IsAzureMonitorTargetEnabled
	if source.IsAzureMonitorTargetEnabled != nil {
		isAzureMonitorTargetEnabled := *source.IsAzureMonitorTargetEnabled
		setting.IsAzureMonitorTargetEnabled = &isAzureMonitorTargetEnabled
	} else {
		setting.IsAzureMonitorTargetEnabled = nil
	}

	// IsManagedIdentityInUse
	if source.IsManagedIdentityInUse != nil {
		isManagedIdentityInUse := *source.IsManagedIdentityInUse
		setting.IsManagedIdentityInUse = &isManagedIdentityInUse
	} else {
		setting.IsManagedIdentityInUse = nil
	}

	// IsStorageSecondaryKeyInUse
	if source.IsStorageSecondaryKeyInUse != nil {
		isStorageSecondaryKeyInUse := *source.IsStorageSecondaryKeyInUse
		setting.IsStorageSecondaryKeyInUse = &isStorageSecondaryKeyInUse
	} else {
		setting.IsStorageSecondaryKeyInUse = nil
	}

	// Kind
	setting.Kind = genruntime.ClonePointerToString(source.Kind)

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

	// QueueDelayMs
	setting.QueueDelayMs = genruntime.ClonePointerToInt(source.QueueDelayMs)

	// RetentionDays
	setting.RetentionDays = genruntime.ClonePointerToInt(source.RetentionDays)

	// State
	if source.State != nil {
		state := *source.State
		stateTemp := genruntime.ToEnum(state, databaseBlobAuditingPolicyProperties_State_STATUS_Values)
		setting.State = &stateTemp
	} else {
		setting.State = nil
	}

	// StorageAccountSubscriptionId
	setting.StorageAccountSubscriptionId = genruntime.ClonePointerToString(source.StorageAccountSubscriptionId)

	// StorageEndpoint
	setting.StorageEndpoint = genruntime.ClonePointerToString(source.StorageEndpoint)

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

	// No error
	return nil
}

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

	// AuditActionsAndGroups
	destination.AuditActionsAndGroups = genruntime.CloneSliceOfString(setting.AuditActionsAndGroups)

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

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

	// IsAzureMonitorTargetEnabled
	if setting.IsAzureMonitorTargetEnabled != nil {
		isAzureMonitorTargetEnabled := *setting.IsAzureMonitorTargetEnabled
		destination.IsAzureMonitorTargetEnabled = &isAzureMonitorTargetEnabled
	} else {
		destination.IsAzureMonitorTargetEnabled = nil
	}

	// IsManagedIdentityInUse
	if setting.IsManagedIdentityInUse != nil {
		isManagedIdentityInUse := *setting.IsManagedIdentityInUse
		destination.IsManagedIdentityInUse = &isManagedIdentityInUse
	} else {
		destination.IsManagedIdentityInUse = nil
	}

	// IsStorageSecondaryKeyInUse
	if setting.IsStorageSecondaryKeyInUse != nil {
		isStorageSecondaryKeyInUse := *setting.IsStorageSecondaryKeyInUse
		destination.IsStorageSecondaryKeyInUse = &isStorageSecondaryKeyInUse
	} else {
		destination.IsStorageSecondaryKeyInUse = nil
	}

	// Kind
	destination.Kind = genruntime.ClonePointerToString(setting.Kind)

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

	// QueueDelayMs
	destination.QueueDelayMs = genruntime.ClonePointerToInt(setting.QueueDelayMs)

	// RetentionDays
	destination.RetentionDays = genruntime.ClonePointerToInt(setting.RetentionDays)

	// State
	if setting.State != nil {
		state := string(*setting.State)
		destination.State = &state
	} else {
		destination.State = nil
	}

	// StorageAccountSubscriptionId
	destination.StorageAccountSubscriptionId = genruntime.ClonePointerToString(setting.StorageAccountSubscriptionId)

	// StorageEndpoint
	destination.StorageEndpoint = genruntime.ClonePointerToString(setting.StorageEndpoint)

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

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

	// No error
	return nil
}

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

const (
	DatabaseBlobAuditingPolicyProperties_State_Disabled = DatabaseBlobAuditingPolicyProperties_State("Disabled")
	DatabaseBlobAuditingPolicyProperties_State_Enabled  = DatabaseBlobAuditingPolicyProperties_State("Enabled")
)

// Mapping from string to DatabaseBlobAuditingPolicyProperties_State
var databaseBlobAuditingPolicyProperties_State_Values = map[string]DatabaseBlobAuditingPolicyProperties_State{
	"disabled": DatabaseBlobAuditingPolicyProperties_State_Disabled,
	"enabled":  DatabaseBlobAuditingPolicyProperties_State_Enabled,
}

type DatabaseBlobAuditingPolicyProperties_State_STATUS string

const (
	DatabaseBlobAuditingPolicyProperties_State_STATUS_Disabled = DatabaseBlobAuditingPolicyProperties_State_STATUS("Disabled")
	DatabaseBlobAuditingPolicyProperties_State_STATUS_Enabled  = DatabaseBlobAuditingPolicyProperties_State_STATUS("Enabled")
)

// Mapping from string to DatabaseBlobAuditingPolicyProperties_State_STATUS
var databaseBlobAuditingPolicyProperties_State_STATUS_Values = map[string]DatabaseBlobAuditingPolicyProperties_State_STATUS{
	"disabled": DatabaseBlobAuditingPolicyProperties_State_STATUS_Disabled,
	"enabled":  DatabaseBlobAuditingPolicyProperties_State_STATUS_Enabled,
}

// Details for configuring operator behavior. Fields in this struct are interpreted by the operator directly rather than being passed to Azure
type ServersDatabasesAuditingSettingOperatorSpec 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_ServersDatabasesAuditingSettingOperatorSpec populates our ServersDatabasesAuditingSettingOperatorSpec from the provided source ServersDatabasesAuditingSettingOperatorSpec
func (operator *ServersDatabasesAuditingSettingOperatorSpec) AssignProperties_From_ServersDatabasesAuditingSettingOperatorSpec(source *storage.ServersDatabasesAuditingSettingOperatorSpec) 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_ServersDatabasesAuditingSettingOperatorSpec populates the provided destination ServersDatabasesAuditingSettingOperatorSpec from our ServersDatabasesAuditingSettingOperatorSpec
func (operator *ServersDatabasesAuditingSettingOperatorSpec) AssignProperties_To_ServersDatabasesAuditingSettingOperatorSpec(destination *storage.ServersDatabasesAuditingSettingOperatorSpec) 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(&ServersDatabasesAuditingSetting{}, &ServersDatabasesAuditingSettingList{})
}
