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

import (
	storage "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20240901/storage"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
	"github.com/rotisserie/eris"
)

// Storage version of v1api20240402preview.AdvancedNetworking
// Advanced Networking profile for enabling observability on a cluster. Note that enabling advanced networking features may
// incur additional costs. For more information see aka.ms/aksadvancednetworking.
type AdvancedNetworking struct {
	Observability *AdvancedNetworkingObservability `json:"observability,omitempty"`
	PropertyBag   genruntime.PropertyBag           `json:"$propertyBag,omitempty"`
}

// AssignProperties_From_AdvancedNetworking populates our AdvancedNetworking from the provided source AdvancedNetworking
func (networking *AdvancedNetworking) AssignProperties_From_AdvancedNetworking(source *storage.AdvancedNetworking) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(source.PropertyBag)

	// Enabled
	if source.Enabled != nil {
		propertyBag.Add("Enabled", *source.Enabled)
	} else {
		propertyBag.Remove("Enabled")
	}

	// Observability
	if source.Observability != nil {
		var observability AdvancedNetworkingObservability
		err := observability.AssignProperties_From_AdvancedNetworkingObservability(source.Observability)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_AdvancedNetworkingObservability() to populate field Observability")
		}
		networking.Observability = &observability
	} else {
		networking.Observability = nil
	}

	// Security
	if source.Security != nil {
		propertyBag.Add("Security", *source.Security)
	} else {
		propertyBag.Remove("Security")
	}

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

	// Invoke the augmentConversionForAdvancedNetworking interface (if implemented) to customize the conversion
	var networkingAsAny any = networking
	if augmentedNetworking, ok := networkingAsAny.(augmentConversionForAdvancedNetworking); ok {
		err := augmentedNetworking.AssignPropertiesFrom(source)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesFrom() for conversion")
		}
	}

	// No error
	return nil
}

// AssignProperties_To_AdvancedNetworking populates the provided destination AdvancedNetworking from our AdvancedNetworking
func (networking *AdvancedNetworking) AssignProperties_To_AdvancedNetworking(destination *storage.AdvancedNetworking) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(networking.PropertyBag)

	// Enabled
	if propertyBag.Contains("Enabled") {
		var enabled bool
		err := propertyBag.Pull("Enabled", &enabled)
		if err != nil {
			return eris.Wrap(err, "pulling 'Enabled' from propertyBag")
		}

		destination.Enabled = &enabled
	} else {
		destination.Enabled = nil
	}

	// Observability
	if networking.Observability != nil {
		var observability storage.AdvancedNetworkingObservability
		err := networking.Observability.AssignProperties_To_AdvancedNetworkingObservability(&observability)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_AdvancedNetworkingObservability() to populate field Observability")
		}
		destination.Observability = &observability
	} else {
		destination.Observability = nil
	}

	// Security
	if propertyBag.Contains("Security") {
		var security storage.AdvancedNetworkingSecurity
		err := propertyBag.Pull("Security", &security)
		if err != nil {
			return eris.Wrap(err, "pulling 'Security' from propertyBag")
		}

		destination.Security = &security
	} else {
		destination.Security = nil
	}

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

	// Invoke the augmentConversionForAdvancedNetworking interface (if implemented) to customize the conversion
	var networkingAsAny any = networking
	if augmentedNetworking, ok := networkingAsAny.(augmentConversionForAdvancedNetworking); ok {
		err := augmentedNetworking.AssignPropertiesTo(destination)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesTo() for conversion")
		}
	}

	// No error
	return nil
}

// Storage version of v1api20240402preview.AdvancedNetworkingObservability
// Observability profile to enable advanced network metrics and flow logs with historical contexts.
type AdvancedNetworkingObservability struct {
	Enabled     *bool                  `json:"enabled,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// AssignProperties_From_AdvancedNetworkingObservability populates our AdvancedNetworkingObservability from the provided source AdvancedNetworkingObservability
func (observability *AdvancedNetworkingObservability) AssignProperties_From_AdvancedNetworkingObservability(source *storage.AdvancedNetworkingObservability) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(source.PropertyBag)

	// Enabled
	if source.Enabled != nil {
		enabled := *source.Enabled
		observability.Enabled = &enabled
	} else {
		observability.Enabled = nil
	}

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

	// Invoke the augmentConversionForAdvancedNetworkingObservability interface (if implemented) to customize the conversion
	var observabilityAsAny any = observability
	if augmentedObservability, ok := observabilityAsAny.(augmentConversionForAdvancedNetworkingObservability); ok {
		err := augmentedObservability.AssignPropertiesFrom(source)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesFrom() for conversion")
		}
	}

	// No error
	return nil
}

// AssignProperties_To_AdvancedNetworkingObservability populates the provided destination AdvancedNetworkingObservability from our AdvancedNetworkingObservability
func (observability *AdvancedNetworkingObservability) AssignProperties_To_AdvancedNetworkingObservability(destination *storage.AdvancedNetworkingObservability) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(observability.PropertyBag)

	// Enabled
	if observability.Enabled != nil {
		enabled := *observability.Enabled
		destination.Enabled = &enabled
	} else {
		destination.Enabled = nil
	}

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

	// Invoke the augmentConversionForAdvancedNetworkingObservability interface (if implemented) to customize the conversion
	var observabilityAsAny any = observability
	if augmentedObservability, ok := observabilityAsAny.(augmentConversionForAdvancedNetworkingObservability); ok {
		err := augmentedObservability.AssignPropertiesTo(destination)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesTo() for conversion")
		}
	}

	// No error
	return nil
}

type augmentConversionForAdvancedNetworking interface {
	AssignPropertiesFrom(src *storage.AdvancedNetworking) error
	AssignPropertiesTo(dst *storage.AdvancedNetworking) error
}

type augmentConversionForAdvancedNetworkingObservability interface {
	AssignPropertiesFrom(src *storage.AdvancedNetworkingObservability) error
	AssignPropertiesTo(dst *storage.AdvancedNetworkingObservability) error
}
