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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/cdn/v1api20230501/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/cdn/v1api20230501/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,cdn}
// +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: /cdn/resource-manager/Microsoft.Cdn/Cdn/stable/2023-05-01/afdx.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/afdEndpoints/{endpointName}
type AfdEndpoint struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              AfdEndpoint_Spec   `json:"spec,omitempty"`
	Status            AfdEndpoint_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &AfdEndpoint{}

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

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

var _ conversion.Convertible = &AfdEndpoint{}

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

	return endpoint.AssignProperties_From_AfdEndpoint(source)
}

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

	return endpoint.AssignProperties_To_AfdEndpoint(destination)
}

var _ configmaps.Exporter = &AfdEndpoint{}

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

var _ secrets.Exporter = &AfdEndpoint{}

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

var _ genruntime.ImportableResource = &AfdEndpoint{}

// InitializeSpec initializes the spec for this resource from the given status
func (endpoint *AfdEndpoint) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*AfdEndpoint_STATUS); ok {
		return endpoint.Spec.Initialize_From_AfdEndpoint_STATUS(s)
	}

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

var _ genruntime.KubernetesResource = &AfdEndpoint{}

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

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

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.Cdn/profiles/afdEndpoints"
func (endpoint *AfdEndpoint) GetType() string {
	return "Microsoft.Cdn/profiles/afdEndpoints"
}

// NewEmptyStatus returns a new empty (blank) status
func (endpoint *AfdEndpoint) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &AfdEndpoint_STATUS{}
}

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

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

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

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

	endpoint.Status = st
	return nil
}

// AssignProperties_From_AfdEndpoint populates our AfdEndpoint from the provided source AfdEndpoint
func (endpoint *AfdEndpoint) AssignProperties_From_AfdEndpoint(source *storage.AfdEndpoint) error {

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

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

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

	// No error
	return nil
}

// AssignProperties_To_AfdEndpoint populates the provided destination AfdEndpoint from our AfdEndpoint
func (endpoint *AfdEndpoint) AssignProperties_To_AfdEndpoint(destination *storage.AfdEndpoint) error {

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

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

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

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /cdn/resource-manager/Microsoft.Cdn/Cdn/stable/2023-05-01/afdx.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/afdEndpoints/{endpointName}
type AfdEndpointList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []AfdEndpoint `json:"items"`
}

type AfdEndpoint_Spec struct {
	// AutoGeneratedDomainNameLabelScope: Indicates the endpoint name reuse scope. The default value is TenantReuse.
	AutoGeneratedDomainNameLabelScope *AutoGeneratedDomainNameLabelScope `json:"autoGeneratedDomainNameLabelScope,omitempty"`

	// AzureName: The name of the resource in Azure. This is often the same as the name of the resource in Kubernetes but it
	// doesn't have to be.
	AzureName string `json:"azureName,omitempty"`

	// EnabledState: Whether to enable use of this rule. Permitted values are 'Enabled' or 'Disabled'
	EnabledState *AFDEndpointProperties_EnabledState `json:"enabledState,omitempty"`

	// +kubebuilder:validation:Required
	// Location: Resource location.
	Location *string `json:"location,omitempty"`

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

	// Tags: Resource tags.
	Tags map[string]string `json:"tags,omitempty"`
}

var _ genruntime.ARMTransformer = &AfdEndpoint_Spec{}

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

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

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

	// Set property "Properties":
	if endpoint.AutoGeneratedDomainNameLabelScope != nil || endpoint.EnabledState != nil {
		result.Properties = &arm.AFDEndpointProperties{}
	}
	if endpoint.AutoGeneratedDomainNameLabelScope != nil {
		var temp string
		temp = string(*endpoint.AutoGeneratedDomainNameLabelScope)
		autoGeneratedDomainNameLabelScope := arm.AutoGeneratedDomainNameLabelScope(temp)
		result.Properties.AutoGeneratedDomainNameLabelScope = &autoGeneratedDomainNameLabelScope
	}
	if endpoint.EnabledState != nil {
		var temp string
		temp = string(*endpoint.EnabledState)
		enabledState := arm.AFDEndpointProperties_EnabledState(temp)
		result.Properties.EnabledState = &enabledState
	}

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

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

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

	// Set property "AutoGeneratedDomainNameLabelScope":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AutoGeneratedDomainNameLabelScope != nil {
			var temp string
			temp = string(*typedInput.Properties.AutoGeneratedDomainNameLabelScope)
			autoGeneratedDomainNameLabelScope := AutoGeneratedDomainNameLabelScope(temp)
			endpoint.AutoGeneratedDomainNameLabelScope = &autoGeneratedDomainNameLabelScope
		}
	}

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

	// Set property "EnabledState":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.EnabledState != nil {
			var temp string
			temp = string(*typedInput.Properties.EnabledState)
			enabledState := AFDEndpointProperties_EnabledState(temp)
			endpoint.EnabledState = &enabledState
		}
	}

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

	// no assignment for property "OperatorSpec"

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

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

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &AfdEndpoint_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.AfdEndpoint_Spec{}
	err := endpoint.AssignProperties_To_AfdEndpoint_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_AfdEndpoint_Spec populates our AfdEndpoint_Spec from the provided source AfdEndpoint_Spec
func (endpoint *AfdEndpoint_Spec) AssignProperties_From_AfdEndpoint_Spec(source *storage.AfdEndpoint_Spec) error {

	// AutoGeneratedDomainNameLabelScope
	if source.AutoGeneratedDomainNameLabelScope != nil {
		autoGeneratedDomainNameLabelScope := *source.AutoGeneratedDomainNameLabelScope
		autoGeneratedDomainNameLabelScopeTemp := genruntime.ToEnum(autoGeneratedDomainNameLabelScope, autoGeneratedDomainNameLabelScope_Values)
		endpoint.AutoGeneratedDomainNameLabelScope = &autoGeneratedDomainNameLabelScopeTemp
	} else {
		endpoint.AutoGeneratedDomainNameLabelScope = nil
	}

	// AzureName
	endpoint.AzureName = source.AzureName

	// EnabledState
	if source.EnabledState != nil {
		enabledState := *source.EnabledState
		enabledStateTemp := genruntime.ToEnum(enabledState, aFDEndpointProperties_EnabledState_Values)
		endpoint.EnabledState = &enabledStateTemp
	} else {
		endpoint.EnabledState = nil
	}

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

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

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

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

	// No error
	return nil
}

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

	// AutoGeneratedDomainNameLabelScope
	if endpoint.AutoGeneratedDomainNameLabelScope != nil {
		autoGeneratedDomainNameLabelScope := string(*endpoint.AutoGeneratedDomainNameLabelScope)
		destination.AutoGeneratedDomainNameLabelScope = &autoGeneratedDomainNameLabelScope
	} else {
		destination.AutoGeneratedDomainNameLabelScope = nil
	}

	// AzureName
	destination.AzureName = endpoint.AzureName

	// EnabledState
	if endpoint.EnabledState != nil {
		enabledState := string(*endpoint.EnabledState)
		destination.EnabledState = &enabledState
	} else {
		destination.EnabledState = nil
	}

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

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

	// OriginalVersion
	destination.OriginalVersion = endpoint.OriginalVersion()

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

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

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

	// No error
	return nil
}

// Initialize_From_AfdEndpoint_STATUS populates our AfdEndpoint_Spec from the provided source AfdEndpoint_STATUS
func (endpoint *AfdEndpoint_Spec) Initialize_From_AfdEndpoint_STATUS(source *AfdEndpoint_STATUS) error {

	// AutoGeneratedDomainNameLabelScope
	if source.AutoGeneratedDomainNameLabelScope != nil {
		autoGeneratedDomainNameLabelScope := genruntime.ToEnum(string(*source.AutoGeneratedDomainNameLabelScope), autoGeneratedDomainNameLabelScope_Values)
		endpoint.AutoGeneratedDomainNameLabelScope = &autoGeneratedDomainNameLabelScope
	} else {
		endpoint.AutoGeneratedDomainNameLabelScope = nil
	}

	// EnabledState
	if source.EnabledState != nil {
		enabledState := genruntime.ToEnum(string(*source.EnabledState), aFDEndpointProperties_EnabledState_Values)
		endpoint.EnabledState = &enabledState
	} else {
		endpoint.EnabledState = nil
	}

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

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

	// No error
	return nil
}

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

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

type AfdEndpoint_STATUS struct {
	// AutoGeneratedDomainNameLabelScope: Indicates the endpoint name reuse scope. The default value is TenantReuse.
	AutoGeneratedDomainNameLabelScope *AutoGeneratedDomainNameLabelScope_STATUS `json:"autoGeneratedDomainNameLabelScope,omitempty"`

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

	// EnabledState: Whether to enable use of this rule. Permitted values are 'Enabled' or 'Disabled'
	EnabledState *AFDEndpointProperties_EnabledState_STATUS `json:"enabledState,omitempty"`

	// HostName: The host name of the endpoint structured as {endpointName}.{DNSZone}, e.g. contoso.azureedge.net
	HostName *string `json:"hostName,omitempty"`

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

	// Location: Resource location.
	Location *string `json:"location,omitempty"`

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

	// ProfileName: The name of the profile which holds the endpoint.
	ProfileName *string `json:"profileName,omitempty"`

	// ProvisioningState: Provisioning status
	ProvisioningState *AFDEndpointProperties_ProvisioningState_STATUS `json:"provisioningState,omitempty"`

	// SystemData: Read only system data
	SystemData *SystemData_STATUS `json:"systemData,omitempty"`

	// Tags: Resource tags.
	Tags map[string]string `json:"tags,omitempty"`

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

var _ genruntime.ConvertibleStatus = &AfdEndpoint_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.AfdEndpoint_STATUS{}
	err := endpoint.AssignProperties_To_AfdEndpoint_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 = &AfdEndpoint_STATUS{}

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

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

	// Set property "AutoGeneratedDomainNameLabelScope":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AutoGeneratedDomainNameLabelScope != nil {
			var temp string
			temp = string(*typedInput.Properties.AutoGeneratedDomainNameLabelScope)
			autoGeneratedDomainNameLabelScope := AutoGeneratedDomainNameLabelScope_STATUS(temp)
			endpoint.AutoGeneratedDomainNameLabelScope = &autoGeneratedDomainNameLabelScope
		}
	}

	// no assignment for property "Conditions"

	// Set property "DeploymentStatus":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.DeploymentStatus != nil {
			var temp string
			temp = string(*typedInput.Properties.DeploymentStatus)
			deploymentStatus := AFDEndpointProperties_DeploymentStatus_STATUS(temp)
			endpoint.DeploymentStatus = &deploymentStatus
		}
	}

	// Set property "EnabledState":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.EnabledState != nil {
			var temp string
			temp = string(*typedInput.Properties.EnabledState)
			enabledState := AFDEndpointProperties_EnabledState_STATUS(temp)
			endpoint.EnabledState = &enabledState
		}
	}

	// Set property "HostName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.HostName != nil {
			hostName := *typedInput.Properties.HostName
			endpoint.HostName = &hostName
		}
	}

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

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

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

	// Set property "ProfileName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ProfileName != nil {
			profileName := *typedInput.Properties.ProfileName
			endpoint.ProfileName = &profileName
		}
	}

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

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

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

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

	// No error
	return nil
}

// AssignProperties_From_AfdEndpoint_STATUS populates our AfdEndpoint_STATUS from the provided source AfdEndpoint_STATUS
func (endpoint *AfdEndpoint_STATUS) AssignProperties_From_AfdEndpoint_STATUS(source *storage.AfdEndpoint_STATUS) error {

	// AutoGeneratedDomainNameLabelScope
	if source.AutoGeneratedDomainNameLabelScope != nil {
		autoGeneratedDomainNameLabelScope := *source.AutoGeneratedDomainNameLabelScope
		autoGeneratedDomainNameLabelScopeTemp := genruntime.ToEnum(autoGeneratedDomainNameLabelScope, autoGeneratedDomainNameLabelScope_STATUS_Values)
		endpoint.AutoGeneratedDomainNameLabelScope = &autoGeneratedDomainNameLabelScopeTemp
	} else {
		endpoint.AutoGeneratedDomainNameLabelScope = nil
	}

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

	// DeploymentStatus
	if source.DeploymentStatus != nil {
		deploymentStatus := *source.DeploymentStatus
		deploymentStatusTemp := genruntime.ToEnum(deploymentStatus, aFDEndpointProperties_DeploymentStatus_STATUS_Values)
		endpoint.DeploymentStatus = &deploymentStatusTemp
	} else {
		endpoint.DeploymentStatus = nil
	}

	// EnabledState
	if source.EnabledState != nil {
		enabledState := *source.EnabledState
		enabledStateTemp := genruntime.ToEnum(enabledState, aFDEndpointProperties_EnabledState_STATUS_Values)
		endpoint.EnabledState = &enabledStateTemp
	} else {
		endpoint.EnabledState = nil
	}

	// HostName
	endpoint.HostName = genruntime.ClonePointerToString(source.HostName)

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

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

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

	// ProfileName
	endpoint.ProfileName = genruntime.ClonePointerToString(source.ProfileName)

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

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

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

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

	// No error
	return nil
}

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

	// AutoGeneratedDomainNameLabelScope
	if endpoint.AutoGeneratedDomainNameLabelScope != nil {
		autoGeneratedDomainNameLabelScope := string(*endpoint.AutoGeneratedDomainNameLabelScope)
		destination.AutoGeneratedDomainNameLabelScope = &autoGeneratedDomainNameLabelScope
	} else {
		destination.AutoGeneratedDomainNameLabelScope = nil
	}

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

	// DeploymentStatus
	if endpoint.DeploymentStatus != nil {
		deploymentStatus := string(*endpoint.DeploymentStatus)
		destination.DeploymentStatus = &deploymentStatus
	} else {
		destination.DeploymentStatus = nil
	}

	// EnabledState
	if endpoint.EnabledState != nil {
		enabledState := string(*endpoint.EnabledState)
		destination.EnabledState = &enabledState
	} else {
		destination.EnabledState = nil
	}

	// HostName
	destination.HostName = genruntime.ClonePointerToString(endpoint.HostName)

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

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

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

	// ProfileName
	destination.ProfileName = genruntime.ClonePointerToString(endpoint.ProfileName)

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

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

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

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

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

	// No error
	return nil
}

// Details for configuring operator behavior. Fields in this struct are interpreted by the operator directly rather than being passed to Azure
type AfdEndpointOperatorSpec 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_AfdEndpointOperatorSpec populates our AfdEndpointOperatorSpec from the provided source AfdEndpointOperatorSpec
func (operator *AfdEndpointOperatorSpec) AssignProperties_From_AfdEndpointOperatorSpec(source *storage.AfdEndpointOperatorSpec) 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_AfdEndpointOperatorSpec populates the provided destination AfdEndpointOperatorSpec from our AfdEndpointOperatorSpec
func (operator *AfdEndpointOperatorSpec) AssignProperties_To_AfdEndpointOperatorSpec(destination *storage.AfdEndpointOperatorSpec) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// ConfigMapExpressions
	if operator.ConfigMapExpressions != nil {
		configMapExpressionList := make([]*core.DestinationExpression, len(operator.ConfigMapExpressions))
		for configMapExpressionIndex, configMapExpressionItem := range operator.ConfigMapExpressions {
			if configMapExpressionItem != nil {
				configMapExpression := *configMapExpressionItem.DeepCopy()
				configMapExpressionList[configMapExpressionIndex] = &configMapExpression
			} else {
				configMapExpressionList[configMapExpressionIndex] = nil
			}
		}
		destination.ConfigMapExpressions = configMapExpressionList
	} else {
		destination.ConfigMapExpressions = nil
	}

	// SecretExpressions
	if operator.SecretExpressions != nil {
		secretExpressionList := make([]*core.DestinationExpression, len(operator.SecretExpressions))
		for secretExpressionIndex, secretExpressionItem := range operator.SecretExpressions {
			if secretExpressionItem != nil {
				secretExpression := *secretExpressionItem.DeepCopy()
				secretExpressionList[secretExpressionIndex] = &secretExpression
			} else {
				secretExpressionList[secretExpressionIndex] = nil
			}
		}
		destination.SecretExpressions = secretExpressionList
	} else {
		destination.SecretExpressions = nil
	}

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

	// No error
	return nil
}

type AFDEndpointProperties_DeploymentStatus_STATUS string

const (
	AFDEndpointProperties_DeploymentStatus_STATUS_Failed     = AFDEndpointProperties_DeploymentStatus_STATUS("Failed")
	AFDEndpointProperties_DeploymentStatus_STATUS_InProgress = AFDEndpointProperties_DeploymentStatus_STATUS("InProgress")
	AFDEndpointProperties_DeploymentStatus_STATUS_NotStarted = AFDEndpointProperties_DeploymentStatus_STATUS("NotStarted")
	AFDEndpointProperties_DeploymentStatus_STATUS_Succeeded  = AFDEndpointProperties_DeploymentStatus_STATUS("Succeeded")
)

// Mapping from string to AFDEndpointProperties_DeploymentStatus_STATUS
var aFDEndpointProperties_DeploymentStatus_STATUS_Values = map[string]AFDEndpointProperties_DeploymentStatus_STATUS{
	"failed":     AFDEndpointProperties_DeploymentStatus_STATUS_Failed,
	"inprogress": AFDEndpointProperties_DeploymentStatus_STATUS_InProgress,
	"notstarted": AFDEndpointProperties_DeploymentStatus_STATUS_NotStarted,
	"succeeded":  AFDEndpointProperties_DeploymentStatus_STATUS_Succeeded,
}

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

const (
	AFDEndpointProperties_EnabledState_Disabled = AFDEndpointProperties_EnabledState("Disabled")
	AFDEndpointProperties_EnabledState_Enabled  = AFDEndpointProperties_EnabledState("Enabled")
)

// Mapping from string to AFDEndpointProperties_EnabledState
var aFDEndpointProperties_EnabledState_Values = map[string]AFDEndpointProperties_EnabledState{
	"disabled": AFDEndpointProperties_EnabledState_Disabled,
	"enabled":  AFDEndpointProperties_EnabledState_Enabled,
}

type AFDEndpointProperties_EnabledState_STATUS string

const (
	AFDEndpointProperties_EnabledState_STATUS_Disabled = AFDEndpointProperties_EnabledState_STATUS("Disabled")
	AFDEndpointProperties_EnabledState_STATUS_Enabled  = AFDEndpointProperties_EnabledState_STATUS("Enabled")
)

// Mapping from string to AFDEndpointProperties_EnabledState_STATUS
var aFDEndpointProperties_EnabledState_STATUS_Values = map[string]AFDEndpointProperties_EnabledState_STATUS{
	"disabled": AFDEndpointProperties_EnabledState_STATUS_Disabled,
	"enabled":  AFDEndpointProperties_EnabledState_STATUS_Enabled,
}

type AFDEndpointProperties_ProvisioningState_STATUS string

const (
	AFDEndpointProperties_ProvisioningState_STATUS_Creating  = AFDEndpointProperties_ProvisioningState_STATUS("Creating")
	AFDEndpointProperties_ProvisioningState_STATUS_Deleting  = AFDEndpointProperties_ProvisioningState_STATUS("Deleting")
	AFDEndpointProperties_ProvisioningState_STATUS_Failed    = AFDEndpointProperties_ProvisioningState_STATUS("Failed")
	AFDEndpointProperties_ProvisioningState_STATUS_Succeeded = AFDEndpointProperties_ProvisioningState_STATUS("Succeeded")
	AFDEndpointProperties_ProvisioningState_STATUS_Updating  = AFDEndpointProperties_ProvisioningState_STATUS("Updating")
)

// Mapping from string to AFDEndpointProperties_ProvisioningState_STATUS
var aFDEndpointProperties_ProvisioningState_STATUS_Values = map[string]AFDEndpointProperties_ProvisioningState_STATUS{
	"creating":  AFDEndpointProperties_ProvisioningState_STATUS_Creating,
	"deleting":  AFDEndpointProperties_ProvisioningState_STATUS_Deleting,
	"failed":    AFDEndpointProperties_ProvisioningState_STATUS_Failed,
	"succeeded": AFDEndpointProperties_ProvisioningState_STATUS_Succeeded,
	"updating":  AFDEndpointProperties_ProvisioningState_STATUS_Updating,
}

// Indicates the endpoint name reuse scope. The default value is TenantReuse.
// +kubebuilder:validation:Enum={"NoReuse","ResourceGroupReuse","SubscriptionReuse","TenantReuse"}
type AutoGeneratedDomainNameLabelScope string

const (
	AutoGeneratedDomainNameLabelScope_NoReuse            = AutoGeneratedDomainNameLabelScope("NoReuse")
	AutoGeneratedDomainNameLabelScope_ResourceGroupReuse = AutoGeneratedDomainNameLabelScope("ResourceGroupReuse")
	AutoGeneratedDomainNameLabelScope_SubscriptionReuse  = AutoGeneratedDomainNameLabelScope("SubscriptionReuse")
	AutoGeneratedDomainNameLabelScope_TenantReuse        = AutoGeneratedDomainNameLabelScope("TenantReuse")
)

// Mapping from string to AutoGeneratedDomainNameLabelScope
var autoGeneratedDomainNameLabelScope_Values = map[string]AutoGeneratedDomainNameLabelScope{
	"noreuse":            AutoGeneratedDomainNameLabelScope_NoReuse,
	"resourcegroupreuse": AutoGeneratedDomainNameLabelScope_ResourceGroupReuse,
	"subscriptionreuse":  AutoGeneratedDomainNameLabelScope_SubscriptionReuse,
	"tenantreuse":        AutoGeneratedDomainNameLabelScope_TenantReuse,
}

// Indicates the endpoint name reuse scope. The default value is TenantReuse.
type AutoGeneratedDomainNameLabelScope_STATUS string

const (
	AutoGeneratedDomainNameLabelScope_STATUS_NoReuse            = AutoGeneratedDomainNameLabelScope_STATUS("NoReuse")
	AutoGeneratedDomainNameLabelScope_STATUS_ResourceGroupReuse = AutoGeneratedDomainNameLabelScope_STATUS("ResourceGroupReuse")
	AutoGeneratedDomainNameLabelScope_STATUS_SubscriptionReuse  = AutoGeneratedDomainNameLabelScope_STATUS("SubscriptionReuse")
	AutoGeneratedDomainNameLabelScope_STATUS_TenantReuse        = AutoGeneratedDomainNameLabelScope_STATUS("TenantReuse")
)

// Mapping from string to AutoGeneratedDomainNameLabelScope_STATUS
var autoGeneratedDomainNameLabelScope_STATUS_Values = map[string]AutoGeneratedDomainNameLabelScope_STATUS{
	"noreuse":            AutoGeneratedDomainNameLabelScope_STATUS_NoReuse,
	"resourcegroupreuse": AutoGeneratedDomainNameLabelScope_STATUS_ResourceGroupReuse,
	"subscriptionreuse":  AutoGeneratedDomainNameLabelScope_STATUS_SubscriptionReuse,
	"tenantreuse":        AutoGeneratedDomainNameLabelScope_STATUS_TenantReuse,
}

func init() {
	SchemeBuilder.Register(&AfdEndpoint{}, &AfdEndpointList{})
}
