// 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 armcognitiveservices

import "encoding/json"

func unmarshalAgentDeploymentPropertiesClassification(rawMsg json.RawMessage) (AgentDeploymentPropertiesClassification, 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 AgentDeploymentPropertiesClassification
	switch m["deploymentType"] {
	case string(AgentDeploymentTypeHosted):
		b = &HostedAgentDeployment{}
	case string(AgentDeploymentTypeManaged):
		b = &ManagedAgentDeployment{}
	default:
		b = &AgentDeploymentProperties{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalApplicationAuthorizationPolicyClassification(rawMsg json.RawMessage) (ApplicationAuthorizationPolicyClassification, 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 ApplicationAuthorizationPolicyClassification
	switch m["type"] {
	case string(BuiltInAuthorizationSchemeChannels):
		b = &ChannelsBuiltInAuthorizationPolicy{}
	case string(BuiltInAuthorizationSchemeDefault):
		b = &RoleBasedBuiltInAuthorizationPolicy{}
	case string(BuiltInAuthorizationSchemeOrganizationScope):
		b = &OrganizationSharedBuiltInAuthorizationPolicy{}
	default:
		b = &ApplicationAuthorizationPolicy{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalComputePropertiesClassification(rawMsg json.RawMessage) (ComputePropertiesClassification, 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 ComputePropertiesClassification
	switch m["computeType"] {
	case string(ComputeTypeCluster):
		b = &ClusterComputeProperties{}
	case string(ComputeTypeContainerInstance):
		b = &ContainerInstanceComputeProperties{}
	default:
		b = &ComputeProperties{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalConnectionPropertiesV2Classification(rawMsg json.RawMessage) (ConnectionPropertiesV2Classification, 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 ConnectionPropertiesV2Classification
	switch m["authType"] {
	case string(ConnectionAuthTypeAAD):
		b = &AADAuthTypeConnectionProperties{}
	case string(ConnectionAuthTypeAPIKey):
		b = &APIKeyAuthConnectionProperties{}
	case string(ConnectionAuthTypeAccessKey):
		b = &AccessKeyAuthTypeConnectionProperties{}
	case string(ConnectionAuthTypeAccountKey):
		b = &AccountKeyAuthTypeConnectionProperties{}
	case string(ConnectionAuthTypeCustomKeys):
		b = &CustomKeysConnectionProperties{}
	case string(ConnectionAuthTypeManagedIdentity):
		b = &ManagedIdentityAuthTypeConnectionProperties{}
	case string(ConnectionAuthTypeNone):
		b = &NoneAuthTypeConnectionProperties{}
	case string(ConnectionAuthTypeOAuth2):
		b = &OAuth2AuthTypeConnectionProperties{}
	case string(ConnectionAuthTypePAT):
		b = &PATAuthTypeConnectionProperties{}
	case string(ConnectionAuthTypeSAS):
		b = &SASAuthTypeConnectionProperties{}
	case string(ConnectionAuthTypeServicePrincipal):
		b = &ServicePrincipalAuthTypeConnectionProperties{}
	case string(ConnectionAuthTypeUsernamePassword):
		b = &UsernamePasswordAuthTypeConnectionProperties{}
	default:
		b = &ConnectionPropertiesV2{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalOutboundRuleClassification(rawMsg json.RawMessage) (OutboundRuleClassification, 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 OutboundRuleClassification
	switch m["type"] {
	case string(RuleTypeFQDN):
		b = &FqdnOutboundRule{}
	case string(RuleTypePrivateEndpoint):
		b = &PrivateEndpointOutboundRule{}
	case string(RuleTypeServiceTag):
		b = &ServiceTagOutboundRule{}
	default:
		b = &OutboundRule{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalOutboundRuleClassificationMap(rawMsg json.RawMessage) (map[string]OutboundRuleClassification, error) {
	if rawMsg == nil || string(rawMsg) == "null" {
		return nil, nil
	}
	var rawMessages map[string]json.RawMessage
	if err := json.Unmarshal(rawMsg, &rawMessages); err != nil {
		return nil, err
	}
	fMap := make(map[string]OutboundRuleClassification, len(rawMessages))
	for key, rawMessage := range rawMessages {
		f, err := unmarshalOutboundRuleClassification(rawMessage)
		if err != nil {
			return nil, err
		}
		fMap[key] = f
	}
	return fMap, nil
}
