// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT.

package armavs

import "encoding/json"

func unmarshalAddonPropertiesClassification(rawMsg json.RawMessage) (AddonPropertiesClassification, error) {
	if rawMsg == nil || string(rawMsg) == "null" {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b AddonPropertiesClassification
	switch m["addonType"] {
	case string(AddonTypeSRM):
		b = &AddonSrmProperties{}
	case string(AddonTypeVR):
		b = &AddonVrProperties{}
	case string(AddonTypeHCX):
		b = &AddonHcxProperties{}
	case string(AddonTypeArc):
		b = &AddonArcProperties{}
	default:
		b = &AddonProperties{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalHostPropertiesClassification(rawMsg json.RawMessage) (HostPropertiesClassification, error) {
	if rawMsg == nil || string(rawMsg) == "null" {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b HostPropertiesClassification
	switch m["kind"] {
	case string(HostKindGeneral):
		b = &GeneralHostProperties{}
	case string(HostKindSpecialized):
		b = &SpecializedHostProperties{}
	default:
		b = &HostProperties{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalPlacementPolicyPropertiesClassification(rawMsg json.RawMessage) (PlacementPolicyPropertiesClassification, error) {
	if rawMsg == nil || string(rawMsg) == "null" {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b PlacementPolicyPropertiesClassification
	switch m["type"] {
	case string(PlacementPolicyTypeVMVM):
		b = &VMPlacementPolicyProperties{}
	case string(PlacementPolicyTypeVMHost):
		b = &VMHostPlacementPolicyProperties{}
	default:
		b = &PlacementPolicyProperties{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalScriptExecutionParameterClassification(rawMsg json.RawMessage) (ScriptExecutionParameterClassification, error) {
	if rawMsg == nil || string(rawMsg) == "null" {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b ScriptExecutionParameterClassification
	switch m["type"] {
	case string(ScriptExecutionParameterTypeSecureValue):
		b = &ScriptSecureStringExecutionParameter{}
	case string(ScriptExecutionParameterTypeValue):
		b = &ScriptStringExecutionParameter{}
	case string(ScriptExecutionParameterTypeCredential):
		b = &PSCredentialExecutionParameter{}
	default:
		b = &ScriptExecutionParameter{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalScriptExecutionParameterClassificationArray(rawMsg json.RawMessage) ([]ScriptExecutionParameterClassification, error) {
	if rawMsg == nil || string(rawMsg) == "null" {
		return nil, nil
	}
	var rawMessages []json.RawMessage
	if err := json.Unmarshal(rawMsg, &rawMessages); err != nil {
		return nil, err
	}
	fArray := make([]ScriptExecutionParameterClassification, len(rawMessages))
	for index, rawMessage := range rawMessages {
		f, err := unmarshalScriptExecutionParameterClassification(rawMessage)
		if err != nil {
			return nil, err
		}
		fArray[index] = f
	}
	return fArray, nil
}

func unmarshalWorkloadNetworkDhcpEntityClassification(rawMsg json.RawMessage) (WorkloadNetworkDhcpEntityClassification, error) {
	if rawMsg == nil || string(rawMsg) == "null" {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b WorkloadNetworkDhcpEntityClassification
	switch m["dhcpType"] {
	case string(DhcpTypeEnumSERVER):
		b = &WorkloadNetworkDhcpServer{}
	case string(DhcpTypeEnumRELAY):
		b = &WorkloadNetworkDhcpRelay{}
	default:
		b = &WorkloadNetworkDhcpEntity{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}
