// Code generated by "gen/generator.go"; DO NOT EDIT.
// In order to regenerate this file execute `go generate` from the repository root.
// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).

package provider

import (
	"context"
	"fmt"
	"reflect"
	"strings"

	"github.com/ciscoecosystem/aci-go-client/v2/client"

	"github.com/hashicorp/terraform-plugin-framework/datasource"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/diag"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
	"github.com/hashicorp/terraform-plugin-log/tflog"
)

// Ensure provider defined types fully satisfy framework interfaces.
var _ datasource.DataSource = &TopSystemDataSource{}

func NewTopSystemDataSource() datasource.DataSource {
	return &TopSystemDataSource{}
}

// TopSystemDataSource defines the data source implementation.
type TopSystemDataSource struct {
	client *client.Client
}

// TopSystemResourceModel describes the resource data model.
type TopSystemResourceModel struct {
	Id                                types.String `tfsdk:"id"`
	Address                           types.String `tfsdk:"address"`
	BootstrapState                    types.String `tfsdk:"bootstrap_state"`
	ClusterTimeDiff                   types.String `tfsdk:"cluster_time_diff"`
	ControlPlaneMTU                   types.String `tfsdk:"control_plane_mtu"`
	CurrentTime                       types.String `tfsdk:"current_time"`
	EnforceSubnetCheck                types.String `tfsdk:"enforce_subnet_check"`
	EtepAddr                          types.String `tfsdk:"external_tep_address"`
	FabricDomain                      types.String `tfsdk:"fabric_domain"`
	FabricId                          types.String `tfsdk:"fabric_id"`
	FabricMAC                         types.String `tfsdk:"fabric_mac"`
	SystemId                          types.String `tfsdk:"system_id"`
	InbMgmtAddr                       types.String `tfsdk:"inband_management_address"`
	InbMgmtAddr6                      types.String `tfsdk:"inband_management_address_ipv6"`
	InbMgmtAddr6Mask                  types.String `tfsdk:"inband_management_address_mask_ipv6"`
	InbMgmtAddrMask                   types.String `tfsdk:"inband_management_address_mask"`
	InbMgmtGateway                    types.String `tfsdk:"inband_management_gateway"`
	InbMgmtGateway6                   types.String `tfsdk:"inband_management_gateway_ipv6"`
	LastRebootTime                    types.String `tfsdk:"last_reboot_time"`
	LastResetReason                   types.String `tfsdk:"last_reset_reason"`
	ModTs                             types.String `tfsdk:"mod_ts"`
	Mode                              types.String `tfsdk:"mode"`
	MonPolDn                          types.String `tfsdk:"monitoring_policy_dn"`
	Name                              types.String `tfsdk:"name"`
	NameAlias                         types.String `tfsdk:"name_alias"`
	NodeType                          types.String `tfsdk:"node_type"`
	OobMgmtAddr                       types.String `tfsdk:"out_of_band_management_address"`
	OobMgmtAddr6                      types.String `tfsdk:"out_of_band_management_address_ipv6"`
	OobMgmtAddr6Mask                  types.String `tfsdk:"out_of_band_management_address_mask_ipv6"`
	OobMgmtAddrMask                   types.String `tfsdk:"out_of_band_management_address_mask"`
	OobMgmtGateway                    types.String `tfsdk:"out_of_band_management_gateway"`
	OobMgmtGateway6                   types.String `tfsdk:"out_of_band_management_gateway_ipv6"`
	PodId                             types.String `tfsdk:"pod_id"`
	RemoteNetworkId                   types.String `tfsdk:"remote_network_id"`
	RemoteNode                        types.String `tfsdk:"remote_node"`
	RlAutoMode                        types.String `tfsdk:"remote_leaf_auto_mode"`
	RlGroupId                         types.String `tfsdk:"remote_leaf_group_id"`
	RlOperPodId                       types.String `tfsdk:"remote_leaf_operational_pod_id"`
	RlRoutableMode                    types.String `tfsdk:"remote_leaf_routable_mode"`
	RldirectMode                      types.String `tfsdk:"remote_leaf_direct_mode"`
	Role                              types.String `tfsdk:"role"`
	Serial                            types.String `tfsdk:"serial"`
	ServerType                        types.String `tfsdk:"server_type"`
	SiteId                            types.String `tfsdk:"site_id"`
	State                             types.String `tfsdk:"state"`
	SystemUpTime                      types.String `tfsdk:"system_uptime"`
	TepPool                           types.String `tfsdk:"tep_pool"`
	UnicastXrEpLearnDisable           types.String `tfsdk:"unicast_xr_endpoint_learn_disable"`
	Version                           types.String `tfsdk:"version"`
	VirtualMode                       types.String `tfsdk:"virtual_mode"`
	DeprecatedEtepAddr                types.String `tfsdk:"etep_addr"`
	DeprecatedOobMgmtAddr             types.String `tfsdk:"oob_mgmt_addr"`
	DeprecatedOobMgmtAddr6            types.String `tfsdk:"oob_mgmt_addr6"`
	DeprecatedOobMgmtAddr6Mask        types.String `tfsdk:"oob_mgmt_addr6_mask"`
	DeprecatedOobMgmtAddrMask         types.String `tfsdk:"oob_mgmt_addr_mask"`
	DeprecatedOobMgmtGateway          types.String `tfsdk:"oob_mgmt_gateway"`
	DeprecatedOobMgmtGateway6         types.String `tfsdk:"oob_mgmt_gateway6"`
	DeprecatedRlAutoMode              types.String `tfsdk:"rl_auto_mode"`
	DeprecatedRlGroupId               types.String `tfsdk:"rl_group_id"`
	DeprecatedRlOperPodId             types.String `tfsdk:"rl_oper_pod_id"`
	DeprecatedRlRoutableMode          types.String `tfsdk:"rl_routable_mode"`
	DeprecatedRldirectMode            types.String `tfsdk:"rldirect_mode"`
	DeprecatedInbMgmtAddr             types.String `tfsdk:"inb_mgmt_addr"`
	DeprecatedInbMgmtAddr6            types.String `tfsdk:"inb_mgmt_addr6"`
	DeprecatedInbMgmtAddr6Mask        types.String `tfsdk:"inb_mgmt_addr6_mask"`
	DeprecatedInbMgmtAddrMask         types.String `tfsdk:"inb_mgmt_addr_mask"`
	DeprecatedInbMgmtGateway          types.String `tfsdk:"inb_mgmt_gateway"`
	DeprecatedInbMgmtGateway6         types.String `tfsdk:"inb_mgmt_gateway6"`
	DeprecatedMonPolDn                types.String `tfsdk:"mon_pol_dn"`
	DeprecatedChildAction             types.String `tfsdk:"child_action"`
	DeprecatedConfigIssues            types.String `tfsdk:"config_issues"`
	DeprecatedLcOwn                   types.String `tfsdk:"lc_own"`
	DeprecatedStatus                  types.String `tfsdk:"status"`
	DeprecatedUnicastXrEpLearnDisable types.String `tfsdk:"unicast_xr_ep_learn_disable"`
	DeprecatedBootstrapState          types.String `tfsdk:"boot_strap_tate"`
}

func (d *TopSystemDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
	tflog.Debug(ctx, "Start metadata of datasource: aci_system")
	resp.TypeName = req.ProviderTypeName + "_system"
	tflog.Debug(ctx, "End metadata of datasource: aci_system")
}

func (d *TopSystemDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
	tflog.Debug(ctx, "Start schema of datasource: aci_system")
	resp.Schema = schema.Schema{
		// This description is used by the documentation generator and the language server.
		MarkdownDescription: "The system datasource for the 'topSystem' class",

		Attributes: map[string]schema.Attribute{
			"id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: "The distinguished name (DN) of the System object.",
			},
			"address": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The IP address of the system.`,
			},
			"bootstrap_state": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Bootstrap state of this system.`,
			},
			"cluster_time_diff": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Difference in cluster time from local time for this system.`,
			},
			"control_plane_mtu": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `MTU for control plane (SUP-originated) packets.`,
			},
			"current_time": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The current time on this system.`,
			},
			"enforce_subnet_check": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Enforce subnet check on all VRFs.`,
			},
			"external_tep_address": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The External TEP IP address of this PoD.`,
			},
			"fabric_domain": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Fabric domain of this node.`,
			},
			"fabric_id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The latest system health score. Use the navigation bar at the top right of the table to select which health level to view.`,
			},
			"fabric_mac": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: ``,
			},
			"system_id": schema.StringAttribute{
				Required:            true,
				MarkdownDescription: `The identifier of the System object.`,
			},
			"inband_management_address": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The in-band management IPv4 address.`,
			},
			"inband_management_address_ipv6": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `In-band management IPv6 address.`,
			},
			"inband_management_address_mask_ipv6": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `In-band management IPv6 address Mask.`,
			},
			"inband_management_address_mask": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `In-band management IP address Mask.`,
			},
			"inband_management_gateway": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `In-band management IP Gateway.`,
			},
			"inband_management_gateway_ipv6": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `In-band management IPv6 Gateway.`,
			},
			"out_of_band_management_address": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The out-of-band management IPv4 address.`,
			},
			"out_of_band_management_address_ipv6": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Out-of-band management IPv6 address.`,
			},
			"out_of_band_management_address_mask_ipv6": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Out-of-band management IPv6 address Mask.`,
			},
			"out_of_band_management_address_mask": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Out-of-band management IP address Mask.`,
			},
			"out_of_band_management_gateway": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Out-of-band management IP Gateway.`,
			},
			"out_of_band_management_gateway_ipv6": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Out-of-band management IPv6 Gateway.`,
			},
			"pod_id": schema.StringAttribute{
				Required:            true,
				MarkdownDescription: `POD Identifier.`,
			},
			"remote_network_id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Remote Network ID.`,
			},
			"remote_node": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Remote system.`,
			},
			"remote_leaf_auto_mode": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Remote Leaf Auto Mode.`,
			},
			"remote_leaf_group_id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Remote Leaf Site Identifier.`,
			},
			"remote_leaf_operational_pod_id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Operational POD Identifier for RL Pod Redundancy.`,
			},
			"remote_leaf_routable_mode": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Is RemoteLeaf Routable.`,
			},
			"remote_leaf_direct_mode": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Remote Leaf Direct Mode.`,
			},
			"last_reboot_time": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `LastRebootTime for this system.`,
			},
			"last_reset_reason": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `LastResetReason for this system.`,
			},
			"mod_ts": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The time when this object was last modified.`,
			},
			"mode": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Specifies if this system is configured in standalone mode or HA pair.`,
			},
			"monitoring_policy_dn": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The monitoring policy attached to this observable object.`,
			},
			"name": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The name of the System object.`,
			},
			"name_alias": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The name alias of the System object.`,
			},
			"node_type": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Role of this system.`,
			},
			"role": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The system role type.`,
			},
			"serial": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Serial Number of the system.`,
			},
			"server_type": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `DhcpServerType.`,
			},
			"site_id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Site Identifier.`,
			},
			"state": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Operational state of this system.`,
			},
			"system_uptime": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `The time (in seconds) since the system was booted.`,
			},
			"tep_pool": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `TepPool for this system.`,
			},
			"unicast_xr_endpoint_learn_disable": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Disable xrLeanrs.`,
			},
			"version": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `version for this system.`,
			},
			"virtual_mode": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: `Virtual mode of system.`,
			},
			"boot_strap_tate": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'boot_strap_tate' will be deprecated soon, please refer to 'bootstrap_state' instead",
			},
			"unicast_xr_ep_learn_disable": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'unicast_xr_ep_learn_disable' will be deprecated soon, please refer to 'unicast_xr_endpoint_learn_disable' instead",
			},
			"etep_addr": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'etep_addr' will be deprecated soon, please refer to 'external_tep_address' instead",
			},
			"inb_mgmt_addr": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'inb_mgmt_addr' will be deprecated soon, please refer to 'inband_management_address' instead",
			},
			"inb_mgmt_addr6": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'inb_mgmt_addr6' will be deprecated soon, please refer to 'inband_management_address_ipv6' instead",
			},
			"inb_mgmt_addr6_mask": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'inb_mgmt_addr6_mask' will be deprecated soon, please refer to 'inband_management_address_mask_ipv6' instead",
			},
			"inb_mgmt_addr_mask": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'inb_mgmt_addr_mask' will be deprecated soon, please refer to 'inband_management_address_mask' instead",
			},
			"inb_mgmt_gateway": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'inb_mgmt_gateway' will be deprecated soon, please refer to 'inband_management_gateway' instead",
			},
			"inb_mgmt_gateway6": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'inb_mgmt_gateway6' will be deprecated soon, please refer to 'inband_management_gateway_ipv6' instead",
			},
			"mon_pol_dn": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'mon_pol_dn' will be deprecated soon, please refer to 'monitoring_policy_dn' instead",
			},
			"oob_mgmt_addr": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'oob_mgmt_addr' will be deprecated soon, please refer to 'out_of_band_management_address' instead",
			},
			"oob_mgmt_addr6": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'oob_mgmt_addr6' will be deprecated soon, please refer to 'out_of_band_management_address_ipv6' instead",
			},
			"oob_mgmt_addr6_mask": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'oob_mgmt_addr6_mask' will be deprecated soon, please refer to 'out_of_band_management_address_mask_ipv6' instead",
			},
			"oob_mgmt_addr_mask": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'oob_mgmt_addr_mask' will be deprecated soon, please refer to 'out_of_band_management_address_mask' instead",
			},
			"oob_mgmt_gateway": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'oob_mgmt_gateway' will be deprecated soon, please refer to 'out_of_band_management_gateway' instead",
			},
			"oob_mgmt_gateway6": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'oob_mgmt_gateway6' will be deprecated soon, please refer to 'out_of_band_management_gateway_ipv6' instead",
			},
			"rl_auto_mode": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'rl_auto_mode' will be deprecated soon, please refer to 'remote_leaf_auto_mode' instead",
			},
			"rl_group_id": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'rl_group_id' will be deprecated soon, please refer to 'remote_leaf_group_id' instead",
			},
			"rl_oper_pod_id": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'rl_oper_pod_id' will be deprecated soon, please refer to 'remote_leaf_operational_pod_id' instead",
			},
			"rl_routable_mode": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'rl_routable_mode' will be deprecated soon, please refer to 'remote_leaf_routable_mode' instead",
			},
			"rldirect_mode": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'rldirect_mode' will be deprecated soon, please refer to 'remote_leaf_direct_mode' instead",
			},
			"child_action": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'child_action' will be deprecated soon",
			},
			"config_issues": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'config_issues' will be deprecated soon",
			},
			"lc_own": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'lc_own' will be deprecated soon",
			},
			"status": schema.StringAttribute{
				Computed:           true,
				DeprecationMessage: "Attribute 'status' will be deprecated soon",
			},
		},
	}
	tflog.Debug(ctx, "End schema of datasource: aci_system")
}

func (d *TopSystemDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
	tflog.Debug(ctx, "Start configure of datasource: aci_system")
	// Prevent panic if the provider has not been configured.
	if req.ProviderData == nil {
		return
	}

	client, ok := req.ProviderData.(*client.Client)

	if !ok {
		resp.Diagnostics.AddError(
			"Unexpected Data Source Configure Type",
			fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
		)

		return
	}

	d.client = client
	tflog.Debug(ctx, "End configure of datasource: aci_system")
}

func (d *TopSystemDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
	tflog.Debug(ctx, "Start read of datasource: aci_system")
	var data *TopSystemResourceModel

	// Read Terraform configuration data into the model
	resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

	if resp.Diagnostics.HasError() {
		return
	}

	setTopSystemId(ctx, data)

	// Create a copy of the Id for when not found during getAndSetTopSystemAttributes
	cachedId := data.Id.ValueString()

	tflog.Debug(ctx, fmt.Sprintf("Read of datasource aci_system with id '%s'", data.Id.ValueString()))

	getAndSetTopSystemAttributes(ctx, &resp.Diagnostics, d.client, data)

	if data.Id.IsNull() {
		resp.Diagnostics.AddError(
			"Failed to read aci_system data source",
			fmt.Sprintf("The aci_system data source with id '%s' has not been found", cachedId),
		)
		return
	}

	// Save data into Terraform state
	resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
	tflog.Debug(ctx, fmt.Sprintf("End read of datasource aci_system with id '%s'", data.Id.ValueString()))
}

func getTopSystemRn(ctx context.Context, data *TopSystemResourceModel) string {
	rn := "pod-{podId}/node-{nodeId}/sys"
	identifiers := map[string]string{
		"podId":  "PodId",
		"nodeId": "SystemId",
	}
	for placeholder, fieldName := range identifiers {
		fieldValue := reflect.ValueOf(data).Elem().FieldByName(fieldName).Interface().(basetypes.StringValue).ValueString()
		rn = strings.ReplaceAll(rn, fmt.Sprintf("{%s}", placeholder), fieldValue)
	}
	return rn
}

func setTopSystemId(ctx context.Context, data *TopSystemResourceModel) {
	rn := getTopSystemRn(ctx, data)
	data.Id = types.StringValue(fmt.Sprintf("%s/%s", "topology", rn))
}

func getAndSetTopSystemAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *TopSystemResourceModel) {
	requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil)

	if diags.HasError() {
		return
	}
	if requestData.Search("imdata").Search("topSystem").Data() != nil {
		classReadInfo := requestData.Search("imdata").Search("topSystem").Data().([]interface{})
		if len(classReadInfo) == 1 {
			attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{})
			for attributeName, attributeValue := range attributes {
				if attributeName == "dn" {
					data.Id = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "address" {
					data.Address = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "bootstrapState" && attributeValue.(string) == "" {
					data.BootstrapState = basetypes.NewStringValue("none")
				} else if attributeName == "bootstrapState" {
					data.BootstrapState = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "clusterTimeDiff" {
					data.ClusterTimeDiff = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "controlPlaneMTU" {
					data.ControlPlaneMTU = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "currentTime" {
					data.CurrentTime = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "enforceSubnetCheck" {
					data.EnforceSubnetCheck = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "etepAddr" {
					data.EtepAddr = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "fabricDomain" {
					data.FabricDomain = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "fabricId" {
					data.FabricId = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "fabricMAC" {
					data.FabricMAC = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "id" {
					data.SystemId = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "inbMgmtAddr" {
					data.InbMgmtAddr = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "inbMgmtAddr6" {
					data.InbMgmtAddr6 = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "inbMgmtAddr6Mask" {
					data.InbMgmtAddr6Mask = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "inbMgmtAddrMask" {
					data.InbMgmtAddrMask = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "inbMgmtGateway" {
					data.InbMgmtGateway = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "inbMgmtGateway6" {
					data.InbMgmtGateway6 = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "lastRebootTime" {
					data.LastRebootTime = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "lastResetReason" {
					data.LastResetReason = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "modTs" {
					data.ModTs = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "mode" {
					data.Mode = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "monPolDn" {
					data.MonPolDn = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "name" {
					data.Name = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "nameAlias" {
					data.NameAlias = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "nodeType" {
					data.NodeType = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "oobMgmtAddr" {
					data.OobMgmtAddr = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "oobMgmtAddr6" {
					data.OobMgmtAddr6 = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "oobMgmtAddr6Mask" {
					data.OobMgmtAddr6Mask = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "oobMgmtAddrMask" {
					data.OobMgmtAddrMask = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "oobMgmtGateway" {
					data.OobMgmtGateway = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "oobMgmtGateway6" {
					data.OobMgmtGateway6 = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "podId" {
					data.PodId = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "remoteNetworkId" {
					data.RemoteNetworkId = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "remoteNode" {
					data.RemoteNode = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "rlAutoMode" {
					data.RlAutoMode = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "rlGroupId" {
					data.RlGroupId = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "rlOperPodId" {
					data.RlOperPodId = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "rlRoutableMode" {
					data.RlRoutableMode = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "rldirectMode" {
					data.RldirectMode = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "role" {
					data.Role = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "serial" {
					data.Serial = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "serverType" {
					data.ServerType = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "siteId" {
					data.SiteId = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "state" {
					data.State = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "systemUpTime" {
					data.SystemUpTime = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "tepPool" {
					data.TepPool = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "unicastXrEpLearnDisable" {
					data.UnicastXrEpLearnDisable = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "version" {
					data.Version = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "virtualMode" {
					data.VirtualMode = basetypes.NewStringValue(attributeValue.(string))
				}
			}
			setTopSystemLegacyAttributes(ctx, diags, data, classReadInfo)
		} else {
			diags.AddError(
				"too many results in response",
				fmt.Sprintf("%v matches returned for class 'topSystem'. Please report this issue to the provider developers.", len(classReadInfo)),
			)
		}
	} else {
		data.Id = basetypes.NewStringNull()
	}
}

func setTopSystemLegacyAttributes(ctx context.Context, diags *diag.Diagnostics, data *TopSystemResourceModel, classReadInfo []interface{}) {
	attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{})
	for attributeName, attributeValue := range attributes {
		if attributeName == "etepAddr" {
			data.DeprecatedEtepAddr = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "inbMgmtAddr" {
			data.DeprecatedInbMgmtAddr = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "inbMgmtAddr6" {
			data.DeprecatedInbMgmtAddr6 = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "inbMgmtAddr6Mask" {
			data.DeprecatedInbMgmtAddr6Mask = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "inbMgmtAddrMask" {
			data.DeprecatedInbMgmtAddrMask = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "inbMgmtGateway" {
			data.DeprecatedInbMgmtGateway = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "inbMgmtGateway6" {
			data.DeprecatedInbMgmtGateway6 = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "monPolDn" {
			data.DeprecatedMonPolDn = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "oobMgmtAddr" {
			data.DeprecatedOobMgmtAddr = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "oobMgmtAddr6" {
			data.DeprecatedOobMgmtAddr6 = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "oobMgmtAddr6Mask" {
			data.DeprecatedOobMgmtAddr6Mask = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "oobMgmtAddrMask" {
			data.DeprecatedOobMgmtAddrMask = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "oobMgmtGateway" {
			data.DeprecatedOobMgmtGateway = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "oobMgmtGateway6" {
			data.DeprecatedOobMgmtGateway6 = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "rlAutoMode" {
			data.DeprecatedRlAutoMode = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "rlGroupId" {
			data.DeprecatedRlGroupId = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "rlOperPodId" {
			data.DeprecatedRlOperPodId = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "rlRoutableMode" {
			data.DeprecatedRlRoutableMode = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "rldirectMode" {
			data.DeprecatedRldirectMode = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "childAction" {
			data.DeprecatedChildAction = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "configIssues" {
			data.DeprecatedConfigIssues = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "lcOwn" {
			data.DeprecatedLcOwn = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "status" {
			data.DeprecatedStatus = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "unicastXrEpLearnDisable" {
			data.DeprecatedUnicastXrEpLearnDisable = basetypes.NewStringValue(attributeValue.(string))
		}
		if attributeName == "bootstrapState" {
			data.DeprecatedBootstrapState = basetypes.NewStringValue(attributeValue.(string))
		}
	}
}
