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

import "encoding/json"

func unmarshalCarbonEmissionDataClassification(rawMsg json.RawMessage) (CarbonEmissionDataClassification, 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 CarbonEmissionDataClassification
	switch m["dataType"] {
	case string(ResponseDataTypeEnumOverallSummaryData):
		b = &CarbonEmissionOverallSummaryData{}
	case string(ResponseDataTypeEnumMonthlySummaryData):
		b = &CarbonEmissionMonthlySummaryData{}
	case string(ResponseDataTypeEnumTopItemsSummaryData):
		b = &CarbonEmissionTopItemsSummaryData{}
	case string(ResponseDataTypeEnumResourceTopItemsSummaryData):
		b = &ResourceCarbonEmissionTopItemsSummaryData{}
	case string(ResponseDataTypeEnumResourceGroupTopItemsSummaryData):
		b = &ResourceGroupCarbonEmissionTopItemsSummaryData{}
	case string(ResponseDataTypeEnumTopItemsMonthlySummaryData):
		b = &CarbonEmissionTopItemMonthlySummaryData{}
	case string(ResponseDataTypeEnumResourceTopItemsMonthlySummaryData):
		b = &ResourceCarbonEmissionTopItemMonthlySummaryData{}
	case string(ResponseDataTypeEnumResourceGroupTopItemsMonthlySummaryData):
		b = &ResourceGroupCarbonEmissionTopItemMonthlySummaryData{}
	case string(ResponseDataTypeEnumItemDetailsData):
		b = &CarbonEmissionItemDetailData{}
	case string(ResponseDataTypeEnumResourceItemDetailsData):
		b = &ResourceCarbonEmissionItemDetailData{}
	case string(ResponseDataTypeEnumResourceGroupItemDetailsData):
		b = &ResourceGroupCarbonEmissionItemDetailData{}
	default:
		b = &CarbonEmissionData{}
	}
	if err := json.Unmarshal(rawMsg, b); err != nil {
		return nil, err
	}
	return b, nil
}

func unmarshalCarbonEmissionDataClassificationArray(rawMsg json.RawMessage) ([]CarbonEmissionDataClassification, 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([]CarbonEmissionDataClassification, len(rawMessages))
	for index, rawMessage := range rawMessages {
		f, err := unmarshalCarbonEmissionDataClassification(rawMessage)
		if err != nil {
			return nil, err
		}
		fArray[index] = f
	}
	return fArray, nil
}
