// 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 v1api20231102preview.AgentPoolSecurityProfile
type AgentPoolSecurityProfile struct {
	EnableSecureBoot *bool                  `json:"enableSecureBoot,omitempty"`
	EnableVTPM       *bool                  `json:"enableVTPM,omitempty"`
	PropertyBag      genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	SshAccess        *string                `json:"sshAccess,omitempty"`
}

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

	// EnableSecureBoot
	if source.EnableSecureBoot != nil {
		enableSecureBoot := *source.EnableSecureBoot
		profile.EnableSecureBoot = &enableSecureBoot
	} else {
		profile.EnableSecureBoot = nil
	}

	// EnableVTPM
	if source.EnableVTPM != nil {
		enableVTPM := *source.EnableVTPM
		profile.EnableVTPM = &enableVTPM
	} else {
		profile.EnableVTPM = nil
	}

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

		profile.SshAccess = &sshAccess
	} else {
		profile.SshAccess = nil
	}

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

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

	// No error
	return nil
}

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

	// EnableSecureBoot
	if profile.EnableSecureBoot != nil {
		enableSecureBoot := *profile.EnableSecureBoot
		destination.EnableSecureBoot = &enableSecureBoot
	} else {
		destination.EnableSecureBoot = nil
	}

	// EnableVTPM
	if profile.EnableVTPM != nil {
		enableVTPM := *profile.EnableVTPM
		destination.EnableVTPM = &enableVTPM
	} else {
		destination.EnableVTPM = nil
	}

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

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

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

	// No error
	return nil
}

type augmentConversionForAgentPoolSecurityProfile interface {
	AssignPropertiesFrom(src *storage.AgentPoolSecurityProfile) error
	AssignPropertiesTo(dst *storage.AgentPoolSecurityProfile) error
}
