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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/cache/v1api20241101/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/cache/v1api20241101/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,cache}
// +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: /redis/resource-manager/Microsoft.Cache/Redis/stable/2024-11-01/redis.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/redis/{name}/patchSchedules/default
type RedisPatchSchedule struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              RedisPatchSchedule_Spec   `json:"spec,omitempty"`
	Status            RedisPatchSchedule_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &RedisPatchSchedule{}

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

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

var _ conversion.Convertible = &RedisPatchSchedule{}

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

	return schedule.AssignProperties_From_RedisPatchSchedule(source)
}

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

	return schedule.AssignProperties_To_RedisPatchSchedule(destination)
}

var _ configmaps.Exporter = &RedisPatchSchedule{}

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

var _ secrets.Exporter = &RedisPatchSchedule{}

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

var _ genruntime.ImportableResource = &RedisPatchSchedule{}

// InitializeSpec initializes the spec for this resource from the given status
func (schedule *RedisPatchSchedule) InitializeSpec(status genruntime.ConvertibleStatus) error {
	if s, ok := status.(*RedisPatchSchedule_STATUS); ok {
		return schedule.Spec.Initialize_From_RedisPatchSchedule_STATUS(s)
	}

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

var _ genruntime.KubernetesResource = &RedisPatchSchedule{}

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

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

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.Cache/redis/patchSchedules"
func (schedule *RedisPatchSchedule) GetType() string {
	return "Microsoft.Cache/redis/patchSchedules"
}

// NewEmptyStatus returns a new empty (blank) status
func (schedule *RedisPatchSchedule) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &RedisPatchSchedule_STATUS{}
}

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

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

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

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

	schedule.Status = st
	return nil
}

// AssignProperties_From_RedisPatchSchedule populates our RedisPatchSchedule from the provided source RedisPatchSchedule
func (schedule *RedisPatchSchedule) AssignProperties_From_RedisPatchSchedule(source *storage.RedisPatchSchedule) error {

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

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

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

	// No error
	return nil
}

// AssignProperties_To_RedisPatchSchedule populates the provided destination RedisPatchSchedule from our RedisPatchSchedule
func (schedule *RedisPatchSchedule) AssignProperties_To_RedisPatchSchedule(destination *storage.RedisPatchSchedule) error {

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

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

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

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /redis/resource-manager/Microsoft.Cache/Redis/stable/2024-11-01/redis.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/redis/{name}/patchSchedules/default
type RedisPatchScheduleList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []RedisPatchSchedule `json:"items"`
}

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

	// +kubebuilder:validation:Required
	// ScheduleEntries: List of patch schedules for a Redis cache.
	ScheduleEntries []ScheduleEntry `json:"scheduleEntries,omitempty"`
}

var _ genruntime.ARMTransformer = &RedisPatchSchedule_Spec{}

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

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

	// Set property "Properties":
	if schedule.ScheduleEntries != nil {
		result.Properties = &arm.ScheduleEntries{}
	}
	for _, item := range schedule.ScheduleEntries {
		item_ARM, err := item.ConvertToARM(resolved)
		if err != nil {
			return nil, err
		}
		result.Properties.ScheduleEntries = append(result.Properties.ScheduleEntries, *item_ARM.(*arm.ScheduleEntry))
	}
	return result, nil
}

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

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

	// no assignment for property "OperatorSpec"

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

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

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &RedisPatchSchedule_Spec{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.RedisPatchSchedule_Spec{}
	err := schedule.AssignProperties_To_RedisPatchSchedule_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_RedisPatchSchedule_Spec populates our RedisPatchSchedule_Spec from the provided source RedisPatchSchedule_Spec
func (schedule *RedisPatchSchedule_Spec) AssignProperties_From_RedisPatchSchedule_Spec(source *storage.RedisPatchSchedule_Spec) error {

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

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

	// ScheduleEntries
	if source.ScheduleEntries != nil {
		scheduleEntryList := make([]ScheduleEntry, len(source.ScheduleEntries))
		for scheduleEntryIndex, scheduleEntryItem := range source.ScheduleEntries {
			var scheduleEntry ScheduleEntry
			err := scheduleEntry.AssignProperties_From_ScheduleEntry(&scheduleEntryItem)
			if err != nil {
				return eris.Wrap(err, "calling AssignProperties_From_ScheduleEntry() to populate field ScheduleEntries")
			}
			scheduleEntryList[scheduleEntryIndex] = scheduleEntry
		}
		schedule.ScheduleEntries = scheduleEntryList
	} else {
		schedule.ScheduleEntries = nil
	}

	// No error
	return nil
}

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

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

	// OriginalVersion
	destination.OriginalVersion = schedule.OriginalVersion()

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

	// ScheduleEntries
	if schedule.ScheduleEntries != nil {
		scheduleEntryList := make([]storage.ScheduleEntry, len(schedule.ScheduleEntries))
		for scheduleEntryIndex, scheduleEntryItem := range schedule.ScheduleEntries {
			var scheduleEntry storage.ScheduleEntry
			err := scheduleEntryItem.AssignProperties_To_ScheduleEntry(&scheduleEntry)
			if err != nil {
				return eris.Wrap(err, "calling AssignProperties_To_ScheduleEntry() to populate field ScheduleEntries")
			}
			scheduleEntryList[scheduleEntryIndex] = scheduleEntry
		}
		destination.ScheduleEntries = scheduleEntryList
	} else {
		destination.ScheduleEntries = nil
	}

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

	// No error
	return nil
}

// Initialize_From_RedisPatchSchedule_STATUS populates our RedisPatchSchedule_Spec from the provided source RedisPatchSchedule_STATUS
func (schedule *RedisPatchSchedule_Spec) Initialize_From_RedisPatchSchedule_STATUS(source *RedisPatchSchedule_STATUS) error {

	// ScheduleEntries
	if source.ScheduleEntries != nil {
		scheduleEntryList := make([]ScheduleEntry, len(source.ScheduleEntries))
		for scheduleEntryIndex, scheduleEntryItem := range source.ScheduleEntries {
			var scheduleEntry ScheduleEntry
			err := scheduleEntry.Initialize_From_ScheduleEntry_STATUS(&scheduleEntryItem)
			if err != nil {
				return eris.Wrap(err, "calling Initialize_From_ScheduleEntry_STATUS() to populate field ScheduleEntries")
			}
			scheduleEntryList[scheduleEntryIndex] = scheduleEntry
		}
		schedule.ScheduleEntries = scheduleEntryList
	} else {
		schedule.ScheduleEntries = nil
	}

	// No error
	return nil
}

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

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

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

	// Location: The geo-location where the resource lives
	Location *string `json:"location,omitempty"`

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

	// ScheduleEntries: List of patch schedules for a Redis cache.
	ScheduleEntries []ScheduleEntry_STATUS `json:"scheduleEntries,omitempty"`

	// SystemData: Azure Resource Manager metadata containing createdBy and modifiedBy information.
	SystemData *SystemData_STATUS `json:"systemData,omitempty"`

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

var _ genruntime.ConvertibleStatus = &RedisPatchSchedule_STATUS{}

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

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

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

	return nil
}

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

	// Convert to an intermediate form
	dst = &storage.RedisPatchSchedule_STATUS{}
	err := schedule.AssignProperties_To_RedisPatchSchedule_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 = &RedisPatchSchedule_STATUS{}

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

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

	// no assignment for property "Conditions"

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

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

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

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

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

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

	// No error
	return nil
}

// AssignProperties_From_RedisPatchSchedule_STATUS populates our RedisPatchSchedule_STATUS from the provided source RedisPatchSchedule_STATUS
func (schedule *RedisPatchSchedule_STATUS) AssignProperties_From_RedisPatchSchedule_STATUS(source *storage.RedisPatchSchedule_STATUS) error {

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

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

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

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

	// ScheduleEntries
	if source.ScheduleEntries != nil {
		scheduleEntryList := make([]ScheduleEntry_STATUS, len(source.ScheduleEntries))
		for scheduleEntryIndex, scheduleEntryItem := range source.ScheduleEntries {
			var scheduleEntry ScheduleEntry_STATUS
			err := scheduleEntry.AssignProperties_From_ScheduleEntry_STATUS(&scheduleEntryItem)
			if err != nil {
				return eris.Wrap(err, "calling AssignProperties_From_ScheduleEntry_STATUS() to populate field ScheduleEntries")
			}
			scheduleEntryList[scheduleEntryIndex] = scheduleEntry
		}
		schedule.ScheduleEntries = scheduleEntryList
	} else {
		schedule.ScheduleEntries = 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")
		}
		schedule.SystemData = &systemDatum
	} else {
		schedule.SystemData = nil
	}

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

	// No error
	return nil
}

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

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

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

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

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

	// ScheduleEntries
	if schedule.ScheduleEntries != nil {
		scheduleEntryList := make([]storage.ScheduleEntry_STATUS, len(schedule.ScheduleEntries))
		for scheduleEntryIndex, scheduleEntryItem := range schedule.ScheduleEntries {
			var scheduleEntry storage.ScheduleEntry_STATUS
			err := scheduleEntryItem.AssignProperties_To_ScheduleEntry_STATUS(&scheduleEntry)
			if err != nil {
				return eris.Wrap(err, "calling AssignProperties_To_ScheduleEntry_STATUS() to populate field ScheduleEntries")
			}
			scheduleEntryList[scheduleEntryIndex] = scheduleEntry
		}
		destination.ScheduleEntries = scheduleEntryList
	} else {
		destination.ScheduleEntries = nil
	}

	// SystemData
	if schedule.SystemData != nil {
		var systemDatum storage.SystemData_STATUS
		err := schedule.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
	}

	// Type
	destination.Type = genruntime.ClonePointerToString(schedule.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 RedisPatchScheduleOperatorSpec 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_RedisPatchScheduleOperatorSpec populates our RedisPatchScheduleOperatorSpec from the provided source RedisPatchScheduleOperatorSpec
func (operator *RedisPatchScheduleOperatorSpec) AssignProperties_From_RedisPatchScheduleOperatorSpec(source *storage.RedisPatchScheduleOperatorSpec) 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_RedisPatchScheduleOperatorSpec populates the provided destination RedisPatchScheduleOperatorSpec from our RedisPatchScheduleOperatorSpec
func (operator *RedisPatchScheduleOperatorSpec) AssignProperties_To_RedisPatchScheduleOperatorSpec(destination *storage.RedisPatchScheduleOperatorSpec) 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
}

// Patch schedule entry for a Premium Redis Cache.
type ScheduleEntry struct {
	// +kubebuilder:validation:Required
	// DayOfWeek: Day of the week when a cache can be patched.
	DayOfWeek *DayOfWeek `json:"dayOfWeek,omitempty"`

	// MaintenanceWindow: ISO8601 timespan specifying how much time cache patching can take.
	MaintenanceWindow *string `json:"maintenanceWindow,omitempty"`

	// +kubebuilder:validation:Required
	// StartHourUtc: Start hour after which cache patching can start.
	StartHourUtc *int `json:"startHourUtc,omitempty"`
}

var _ genruntime.ARMTransformer = &ScheduleEntry{}

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

	// Set property "DayOfWeek":
	if entry.DayOfWeek != nil {
		var temp string
		temp = string(*entry.DayOfWeek)
		dayOfWeek := arm.DayOfWeek(temp)
		result.DayOfWeek = &dayOfWeek
	}

	// Set property "MaintenanceWindow":
	if entry.MaintenanceWindow != nil {
		maintenanceWindow := *entry.MaintenanceWindow
		result.MaintenanceWindow = &maintenanceWindow
	}

	// Set property "StartHourUtc":
	if entry.StartHourUtc != nil {
		startHourUtc := *entry.StartHourUtc
		result.StartHourUtc = &startHourUtc
	}
	return result, nil
}

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

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

	// Set property "DayOfWeek":
	if typedInput.DayOfWeek != nil {
		var temp string
		temp = string(*typedInput.DayOfWeek)
		dayOfWeek := DayOfWeek(temp)
		entry.DayOfWeek = &dayOfWeek
	}

	// Set property "MaintenanceWindow":
	if typedInput.MaintenanceWindow != nil {
		maintenanceWindow := *typedInput.MaintenanceWindow
		entry.MaintenanceWindow = &maintenanceWindow
	}

	// Set property "StartHourUtc":
	if typedInput.StartHourUtc != nil {
		startHourUtc := *typedInput.StartHourUtc
		entry.StartHourUtc = &startHourUtc
	}

	// No error
	return nil
}

// AssignProperties_From_ScheduleEntry populates our ScheduleEntry from the provided source ScheduleEntry
func (entry *ScheduleEntry) AssignProperties_From_ScheduleEntry(source *storage.ScheduleEntry) error {

	// DayOfWeek
	if source.DayOfWeek != nil {
		dayOfWeek := *source.DayOfWeek
		dayOfWeekTemp := genruntime.ToEnum(dayOfWeek, dayOfWeek_Values)
		entry.DayOfWeek = &dayOfWeekTemp
	} else {
		entry.DayOfWeek = nil
	}

	// MaintenanceWindow
	entry.MaintenanceWindow = genruntime.ClonePointerToString(source.MaintenanceWindow)

	// StartHourUtc
	entry.StartHourUtc = genruntime.ClonePointerToInt(source.StartHourUtc)

	// No error
	return nil
}

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

	// DayOfWeek
	if entry.DayOfWeek != nil {
		dayOfWeek := string(*entry.DayOfWeek)
		destination.DayOfWeek = &dayOfWeek
	} else {
		destination.DayOfWeek = nil
	}

	// MaintenanceWindow
	destination.MaintenanceWindow = genruntime.ClonePointerToString(entry.MaintenanceWindow)

	// StartHourUtc
	destination.StartHourUtc = genruntime.ClonePointerToInt(entry.StartHourUtc)

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

	// No error
	return nil
}

// Initialize_From_ScheduleEntry_STATUS populates our ScheduleEntry from the provided source ScheduleEntry_STATUS
func (entry *ScheduleEntry) Initialize_From_ScheduleEntry_STATUS(source *ScheduleEntry_STATUS) error {

	// DayOfWeek
	if source.DayOfWeek != nil {
		dayOfWeek := genruntime.ToEnum(string(*source.DayOfWeek), dayOfWeek_Values)
		entry.DayOfWeek = &dayOfWeek
	} else {
		entry.DayOfWeek = nil
	}

	// MaintenanceWindow
	entry.MaintenanceWindow = genruntime.ClonePointerToString(source.MaintenanceWindow)

	// StartHourUtc
	entry.StartHourUtc = genruntime.ClonePointerToInt(source.StartHourUtc)

	// No error
	return nil
}

// Patch schedule entry for a Premium Redis Cache.
type ScheduleEntry_STATUS struct {
	// DayOfWeek: Day of the week when a cache can be patched.
	DayOfWeek *DayOfWeek_STATUS `json:"dayOfWeek,omitempty"`

	// MaintenanceWindow: ISO8601 timespan specifying how much time cache patching can take.
	MaintenanceWindow *string `json:"maintenanceWindow,omitempty"`

	// StartHourUtc: Start hour after which cache patching can start.
	StartHourUtc *int `json:"startHourUtc,omitempty"`
}

var _ genruntime.FromARMConverter = &ScheduleEntry_STATUS{}

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

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

	// Set property "DayOfWeek":
	if typedInput.DayOfWeek != nil {
		var temp string
		temp = string(*typedInput.DayOfWeek)
		dayOfWeek := DayOfWeek_STATUS(temp)
		entry.DayOfWeek = &dayOfWeek
	}

	// Set property "MaintenanceWindow":
	if typedInput.MaintenanceWindow != nil {
		maintenanceWindow := *typedInput.MaintenanceWindow
		entry.MaintenanceWindow = &maintenanceWindow
	}

	// Set property "StartHourUtc":
	if typedInput.StartHourUtc != nil {
		startHourUtc := *typedInput.StartHourUtc
		entry.StartHourUtc = &startHourUtc
	}

	// No error
	return nil
}

// AssignProperties_From_ScheduleEntry_STATUS populates our ScheduleEntry_STATUS from the provided source ScheduleEntry_STATUS
func (entry *ScheduleEntry_STATUS) AssignProperties_From_ScheduleEntry_STATUS(source *storage.ScheduleEntry_STATUS) error {

	// DayOfWeek
	if source.DayOfWeek != nil {
		dayOfWeek := *source.DayOfWeek
		dayOfWeekTemp := genruntime.ToEnum(dayOfWeek, dayOfWeek_STATUS_Values)
		entry.DayOfWeek = &dayOfWeekTemp
	} else {
		entry.DayOfWeek = nil
	}

	// MaintenanceWindow
	entry.MaintenanceWindow = genruntime.ClonePointerToString(source.MaintenanceWindow)

	// StartHourUtc
	entry.StartHourUtc = genruntime.ClonePointerToInt(source.StartHourUtc)

	// No error
	return nil
}

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

	// DayOfWeek
	if entry.DayOfWeek != nil {
		dayOfWeek := string(*entry.DayOfWeek)
		destination.DayOfWeek = &dayOfWeek
	} else {
		destination.DayOfWeek = nil
	}

	// MaintenanceWindow
	destination.MaintenanceWindow = genruntime.ClonePointerToString(entry.MaintenanceWindow)

	// StartHourUtc
	destination.StartHourUtc = genruntime.ClonePointerToInt(entry.StartHourUtc)

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

	// No error
	return nil
}

// Day of the week when a cache can be patched.
// +kubebuilder:validation:Enum={"Everyday","Friday","Monday","Saturday","Sunday","Thursday","Tuesday","Wednesday","Weekend"}
type DayOfWeek string

const (
	DayOfWeek_Everyday  = DayOfWeek("Everyday")
	DayOfWeek_Friday    = DayOfWeek("Friday")
	DayOfWeek_Monday    = DayOfWeek("Monday")
	DayOfWeek_Saturday  = DayOfWeek("Saturday")
	DayOfWeek_Sunday    = DayOfWeek("Sunday")
	DayOfWeek_Thursday  = DayOfWeek("Thursday")
	DayOfWeek_Tuesday   = DayOfWeek("Tuesday")
	DayOfWeek_Wednesday = DayOfWeek("Wednesday")
	DayOfWeek_Weekend   = DayOfWeek("Weekend")
)

// Mapping from string to DayOfWeek
var dayOfWeek_Values = map[string]DayOfWeek{
	"everyday":  DayOfWeek_Everyday,
	"friday":    DayOfWeek_Friday,
	"monday":    DayOfWeek_Monday,
	"saturday":  DayOfWeek_Saturday,
	"sunday":    DayOfWeek_Sunday,
	"thursday":  DayOfWeek_Thursday,
	"tuesday":   DayOfWeek_Tuesday,
	"wednesday": DayOfWeek_Wednesday,
	"weekend":   DayOfWeek_Weekend,
}

// Day of the week when a cache can be patched.
type DayOfWeek_STATUS string

const (
	DayOfWeek_STATUS_Everyday  = DayOfWeek_STATUS("Everyday")
	DayOfWeek_STATUS_Friday    = DayOfWeek_STATUS("Friday")
	DayOfWeek_STATUS_Monday    = DayOfWeek_STATUS("Monday")
	DayOfWeek_STATUS_Saturday  = DayOfWeek_STATUS("Saturday")
	DayOfWeek_STATUS_Sunday    = DayOfWeek_STATUS("Sunday")
	DayOfWeek_STATUS_Thursday  = DayOfWeek_STATUS("Thursday")
	DayOfWeek_STATUS_Tuesday   = DayOfWeek_STATUS("Tuesday")
	DayOfWeek_STATUS_Wednesday = DayOfWeek_STATUS("Wednesday")
	DayOfWeek_STATUS_Weekend   = DayOfWeek_STATUS("Weekend")
)

// Mapping from string to DayOfWeek_STATUS
var dayOfWeek_STATUS_Values = map[string]DayOfWeek_STATUS{
	"everyday":  DayOfWeek_STATUS_Everyday,
	"friday":    DayOfWeek_STATUS_Friday,
	"monday":    DayOfWeek_STATUS_Monday,
	"saturday":  DayOfWeek_STATUS_Saturday,
	"sunday":    DayOfWeek_STATUS_Sunday,
	"thursday":  DayOfWeek_STATUS_Thursday,
	"tuesday":   DayOfWeek_STATUS_Tuesday,
	"wednesday": DayOfWeek_STATUS_Wednesday,
	"weekend":   DayOfWeek_STATUS_Weekend,
}

func init() {
	SchemeBuilder.Register(&RedisPatchSchedule{}, &RedisPatchScheduleList{})
}
