//go:build go1.18
// +build go1.18

// 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) AutoRest Code Generator. DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package armauthorization

import "encoding/json"

func unmarshalAccessReviewDecisionIdentityClassification(rawMsg json.RawMessage) (AccessReviewDecisionIdentityClassification, error) {
	if rawMsg == nil {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b AccessReviewDecisionIdentityClassification
	switch m["type"] {
	case string(DecisionTargetTypeServicePrincipal):
		b = &AccessReviewDecisionServicePrincipalIdentity{}
	case string(DecisionTargetTypeUser):
		b = &AccessReviewDecisionUserIdentity{}
	default:
		b = &AccessReviewDecisionIdentity{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalAccessReviewDecisionInsightPropertiesClassification(rawMsg json.RawMessage) (AccessReviewDecisionInsightPropertiesClassification, error) {
	if rawMsg == nil {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b AccessReviewDecisionInsightPropertiesClassification
	switch m["type"] {
	case string(AccessReviewDecisionInsightTypeUserSignInInsight):
		b = &AccessReviewDecisionUserSignInInsightProperties{}
	default:
		b = &AccessReviewDecisionInsightProperties{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalAlertConfigurationPropertiesClassification(rawMsg json.RawMessage) (AlertConfigurationPropertiesClassification, error) {
	if rawMsg == nil {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b AlertConfigurationPropertiesClassification
	switch m["alertConfigurationType"] {
	case "AzureRolesAssignedOutsidePimAlertConfiguration":
		b = &AzureRolesAssignedOutsidePimAlertConfigurationProperties{}
	case "DuplicateRoleCreatedAlertConfiguration":
		b = &DuplicateRoleCreatedAlertConfigurationProperties{}
	case "TooManyOwnersAssignedToResourceAlertConfiguration":
		b = &TooManyOwnersAssignedToResourceAlertConfigurationProperties{}
	case "TooManyPermanentOwnersAssignedToResourceAlertConfiguration":
		b = &TooManyPermanentOwnersAssignedToResourceAlertConfigurationProperties{}
	default:
		b = &AlertConfigurationProperties{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalAlertIncidentPropertiesClassification(rawMsg json.RawMessage) (AlertIncidentPropertiesClassification, error) {
	if rawMsg == nil {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b AlertIncidentPropertiesClassification
	switch m["alertIncidentType"] {
	case "AzureRolesAssignedOutsidePimAlertIncident":
		b = &AzureRolesAssignedOutsidePimAlertIncidentProperties{}
	case "DuplicateRoleCreatedAlertIncident":
		b = &DuplicateRoleCreatedAlertIncidentProperties{}
	case "TooManyOwnersAssignedToResourceAlertIncident":
		b = &TooManyOwnersAssignedToResourceAlertIncidentProperties{}
	case "TooManyPermanentOwnersAssignedToResourceAlertIncident":
		b = &TooManyPermanentOwnersAssignedToResourceAlertIncidentProperties{}
	default:
		b = &AlertIncidentProperties{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalRoleManagementPolicyRuleClassification(rawMsg json.RawMessage) (RoleManagementPolicyRuleClassification, error) {
	if rawMsg == nil {
		return nil, nil
	}
	var m map[string]any
	if err := json.Unmarshal(rawMsg, &m); err != nil {
		return nil, err
	}
	var b RoleManagementPolicyRuleClassification
	switch m["ruleType"] {
	case string(RoleManagementPolicyRuleTypeRoleManagementPolicyApprovalRule):
		b = &RoleManagementPolicyApprovalRule{}
	case string(RoleManagementPolicyRuleTypeRoleManagementPolicyAuthenticationContextRule):
		b = &RoleManagementPolicyAuthenticationContextRule{}
	case string(RoleManagementPolicyRuleTypeRoleManagementPolicyEnablementRule):
		b = &RoleManagementPolicyEnablementRule{}
	case string(RoleManagementPolicyRuleTypeRoleManagementPolicyExpirationRule):
		b = &RoleManagementPolicyExpirationRule{}
	case string(RoleManagementPolicyRuleTypeRoleManagementPolicyNotificationRule):
		b = &RoleManagementPolicyNotificationRule{}
	default:
		b = &RoleManagementPolicyRule{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalRoleManagementPolicyRuleClassificationArray(rawMsg json.RawMessage) ([]RoleManagementPolicyRuleClassification, error) {
	if rawMsg == nil {
		return nil, nil
	}
	var rawMessages []json.RawMessage
	if err := json.Unmarshal(rawMsg, &rawMessages); err != nil {
		return nil, err
	}
	fArray := make([]RoleManagementPolicyRuleClassification, len(rawMessages))
	for index, rawMessage := range rawMessages {
		f, err := unmarshalRoleManagementPolicyRuleClassification(rawMessage)
		if err != nil {
			return nil, err
		}
		fArray[index] = f
	}
	return fArray, nil
}
