// 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"
	"encoding/json"
	"fmt"

	"github.com/ciscoecosystem/aci-go-client/v2/client"
	"github.com/ciscoecosystem/aci-go-client/v2/container"
	"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
	"github.com/hashicorp/terraform-plugin-framework/attr"
	"github.com/hashicorp/terraform-plugin-framework/diag"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/resource"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"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 _ resource.Resource = &FvTrackListResource{}
var _ resource.ResourceWithImportState = &FvTrackListResource{}

func NewFvTrackListResource() resource.Resource {
	return &FvTrackListResource{}
}

// FvTrackListResource defines the resource implementation.
type FvTrackListResource struct {
	client *client.Client
}

// FvTrackListResourceModel describes the resource data model.
type FvTrackListResourceModel struct {
	Id                types.String `tfsdk:"id"`
	ParentDn          types.String `tfsdk:"parent_dn"`
	Annotation        types.String `tfsdk:"annotation"`
	Descr             types.String `tfsdk:"description"`
	Name              types.String `tfsdk:"name"`
	NameAlias         types.String `tfsdk:"name_alias"`
	OwnerKey          types.String `tfsdk:"owner_key"`
	OwnerTag          types.String `tfsdk:"owner_tag"`
	PercentageDown    types.String `tfsdk:"percentage_down"`
	PercentageUp      types.String `tfsdk:"percentage_up"`
	Type              types.String `tfsdk:"type"`
	WeightDown        types.String `tfsdk:"weight_down"`
	WeightUp          types.String `tfsdk:"weight_up"`
	FvRsOtmListMember types.Set    `tfsdk:"relation_to_ip_sla_track_members"`
	TagAnnotation     types.Set    `tfsdk:"annotations"`
	TagTag            types.Set    `tfsdk:"tags"`
}

func getEmptyFvTrackListResourceModel() *FvTrackListResourceModel {
	return &FvTrackListResourceModel{
		Id:             basetypes.NewStringNull(),
		ParentDn:       basetypes.NewStringNull(),
		Annotation:     basetypes.NewStringNull(),
		Descr:          basetypes.NewStringNull(),
		Name:           basetypes.NewStringNull(),
		NameAlias:      basetypes.NewStringNull(),
		OwnerKey:       basetypes.NewStringNull(),
		OwnerTag:       basetypes.NewStringNull(),
		PercentageDown: basetypes.NewStringNull(),
		PercentageUp:   basetypes.NewStringNull(),
		Type:           basetypes.NewStringNull(),
		WeightDown:     basetypes.NewStringNull(),
		WeightUp:       basetypes.NewStringNull(),
		FvRsOtmListMember: types.SetNull(types.ObjectType{
			AttrTypes: map[string]attr.Type{
				"annotation":  types.StringType,
				"target_dn":   types.StringType,
				"weight":      types.StringType,
				"annotations": types.SetType{ElemType: TagAnnotationFvRsOtmListMemberFvTrackListType},
				"tags":        types.SetType{ElemType: TagTagFvRsOtmListMemberFvTrackListType},
			},
		}),
		TagAnnotation: types.SetNull(types.ObjectType{
			AttrTypes: map[string]attr.Type{
				"key":   types.StringType,
				"value": types.StringType,
			},
		}),
		TagTag: types.SetNull(types.ObjectType{
			AttrTypes: map[string]attr.Type{
				"key":   types.StringType,
				"value": types.StringType,
			},
		}),
	}
}

// FvRsOtmListMemberFvTrackListResourceModel describes the resource data model for the children without relation ships.
type FvRsOtmListMemberFvTrackListResourceModel struct {
	Annotation    types.String `tfsdk:"annotation"`
	TDn           types.String `tfsdk:"target_dn"`
	Weight        types.String `tfsdk:"weight"`
	TagAnnotation types.Set    `tfsdk:"annotations"`
	TagTag        types.Set    `tfsdk:"tags"`
}

func getEmptyFvRsOtmListMemberFvTrackListResourceModel() FvRsOtmListMemberFvTrackListResourceModel {
	return FvRsOtmListMemberFvTrackListResourceModel{
		Annotation: basetypes.NewStringNull(),
		TDn:        basetypes.NewStringNull(),
		Weight:     basetypes.NewStringNull(),
		TagAnnotation: types.SetNull(types.ObjectType{
			AttrTypes: map[string]attr.Type{
				"key":   types.StringType,
				"value": types.StringType,
			},
		}),
		TagTag: types.SetNull(types.ObjectType{
			AttrTypes: map[string]attr.Type{
				"key":   types.StringType,
				"value": types.StringType,
			},
		}),
	}
}

var FvRsOtmListMemberFvTrackListType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"annotation":  types.StringType,
		"target_dn":   types.StringType,
		"weight":      types.StringType,
		"annotations": types.SetType{ElemType: TagAnnotationFvRsOtmListMemberFvTrackListType},
		"tags":        types.SetType{ElemType: TagTagFvRsOtmListMemberFvTrackListType},
	},
}

func FvRsOtmListMemberFvTrackListSetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate(ctx context.Context, planValue, stateValue types.Set) basetypes.SetValue {
	//  Function is needed to handle the case that an attribute is not yet supported in a version and gets set to null during read
	var planSetValues, stateSetValues []FvRsOtmListMemberFvTrackListResourceModel
	stateValue.ElementsAs(ctx, &stateSetValues, false)
	planValue.ElementsAs(ctx, &planSetValues, false)

	// If the length of the state and plan values are different a change is already detected the loop can be skipped
	if len(stateSetValues) == len(planSetValues) {
		for index, stateValue := range stateSetValues {
			nullInStateFound := false
			if stateValue.Annotation.IsNull() {
				nullInStateFound = true
				planSetValues[index].Annotation = basetypes.NewStringNull()
			}
			if stateValue.TDn.IsNull() {
				nullInStateFound = true
				planSetValues[index].TDn = basetypes.NewStringNull()
			}
			if stateValue.Weight.IsNull() {
				nullInStateFound = true
				planSetValues[index].Weight = basetypes.NewStringNull()
			}
			if !nullInStateFound {
				// when there are no null fields we can conclude the version supports all attributes in set
				break
			}
		}
	}
	planSet, _ := types.SetValueFrom(ctx, FvRsOtmListMemberFvTrackListType, planSetValues)
	return planSet

}

// TagAnnotationFvRsOtmListMemberFvTrackListResourceModel describes the resource data model for the children without relation ships.
type TagAnnotationFvRsOtmListMemberFvTrackListResourceModel struct {
	Key   types.String `tfsdk:"key"`
	Value types.String `tfsdk:"value"`
}

func getEmptyTagAnnotationFvRsOtmListMemberFvTrackListResourceModel() TagAnnotationFvRsOtmListMemberFvTrackListResourceModel {
	return TagAnnotationFvRsOtmListMemberFvTrackListResourceModel{
		Key:   basetypes.NewStringNull(),
		Value: basetypes.NewStringNull(),
	}
}

var TagAnnotationFvRsOtmListMemberFvTrackListType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"key":   types.StringType,
		"value": types.StringType,
	},
}

// TagTagFvRsOtmListMemberFvTrackListResourceModel describes the resource data model for the children without relation ships.
type TagTagFvRsOtmListMemberFvTrackListResourceModel struct {
	Key   types.String `tfsdk:"key"`
	Value types.String `tfsdk:"value"`
}

func getEmptyTagTagFvRsOtmListMemberFvTrackListResourceModel() TagTagFvRsOtmListMemberFvTrackListResourceModel {
	return TagTagFvRsOtmListMemberFvTrackListResourceModel{
		Key:   basetypes.NewStringNull(),
		Value: basetypes.NewStringNull(),
	}
}

var TagTagFvRsOtmListMemberFvTrackListType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"key":   types.StringType,
		"value": types.StringType,
	},
}

// TagAnnotationFvTrackListResourceModel describes the resource data model for the children without relation ships.
type TagAnnotationFvTrackListResourceModel struct {
	Key   types.String `tfsdk:"key"`
	Value types.String `tfsdk:"value"`
}

func getEmptyTagAnnotationFvTrackListResourceModel() TagAnnotationFvTrackListResourceModel {
	return TagAnnotationFvTrackListResourceModel{
		Key:   basetypes.NewStringNull(),
		Value: basetypes.NewStringNull(),
	}
}

var TagAnnotationFvTrackListType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"key":   types.StringType,
		"value": types.StringType,
	},
}

// TagTagFvTrackListResourceModel describes the resource data model for the children without relation ships.
type TagTagFvTrackListResourceModel struct {
	Key   types.String `tfsdk:"key"`
	Value types.String `tfsdk:"value"`
}

func getEmptyTagTagFvTrackListResourceModel() TagTagFvTrackListResourceModel {
	return TagTagFvTrackListResourceModel{
		Key:   basetypes.NewStringNull(),
		Value: basetypes.NewStringNull(),
	}
}

var TagTagFvTrackListType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"key":   types.StringType,
		"value": types.StringType,
	},
}

type FvTrackListIdentifier struct {
	Name types.String
}

func (r *FvTrackListResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
	if !req.Plan.Raw.IsNull() {
		var planData, stateData *FvTrackListResourceModel
		resp.Diagnostics.Append(req.Plan.Get(ctx, &planData)...)
		resp.Diagnostics.Append(req.State.Get(ctx, &stateData)...)

		if resp.Diagnostics.HasError() {
			return
		}

		if (planData.Id.IsUnknown() || planData.Id.IsNull()) && !planData.ParentDn.IsUnknown() && !planData.Name.IsUnknown() {
			setFvTrackListId(ctx, planData)
		}

		if stateData == nil && !globalAllowExistingOnCreate && !planData.Id.IsUnknown() && !planData.Id.IsNull() {
			CheckDn(ctx, &resp.Diagnostics, r.client, "fvTrackList", planData.Id.ValueString())
			if resp.Diagnostics.HasError() {
				return
			}
		}

		resp.Diagnostics.Append(resp.Plan.Set(ctx, &planData)...)
	}
}

func (r *FvTrackListResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
	tflog.Debug(ctx, "Start metadata of resource: aci_ip_sla_track_list")
	resp.TypeName = req.ProviderTypeName + "_ip_sla_track_list"
	tflog.Debug(ctx, "End metadata of resource: aci_ip_sla_track_list")
}

func (r *FvTrackListResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
	tflog.Debug(ctx, "Start schema of resource: aci_ip_sla_track_list")
	resp.Schema = schema.Schema{
		// This description is used by the documentation generator and the language server.
		MarkdownDescription: "The ip_sla_track_list resource for the 'fvTrackList' class",

		Attributes: map[string]schema.Attribute{
			"id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: "The distinguished name (DN) of the IP SLA Track List object.",
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
				},
			},
			"parent_dn": schema.StringAttribute{
				Required:            true,
				MarkdownDescription: "The distinguished name (DN) of the parent object.",
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					stringplanmodifier.RequiresReplace(),
				},
			},
			"annotation": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				Default:             stringdefault.StaticString(globalAnnotation),
				MarkdownDescription: `The annotation of the IP SLA Track List object.`,
			},
			"description": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The description of the IP SLA Track List object.`,
			},
			"name": schema.StringAttribute{
				Required: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
					stringplanmodifier.RequiresReplace(),
				},
				MarkdownDescription: `The name of the IP SLA Track List object.`,
			},
			"name_alias": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The name alias of the IP SLA Track List object.`,
			},
			"owner_key": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`,
			},
			"owner_tag": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`,
			},
			"percentage_down": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The down percentage assigned to the IP SLA Track List determines whether a route is considered available or unavailable. This attribute is applicable only when the track type is 'percentage'.`,
			},
			"percentage_up": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The up percentage assigned to the IP SLA Track List determines whether a route is considered available or unavailable. The percentage up must be greater than the percentage down. This attribute is applicable only when the track type is 'percentage'.`,
			},
			"type": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
					stringplanmodifier.RequiresReplace(),
				},
				Validators: []validator.String{
					stringvalidator.OneOf("percentage", "weight"),
				},
				MarkdownDescription: `The type of the IP SLA Track List. Choose 'percentage' if you want the route availability to be based on the percentage of track members that are up or down. Choose 'weight' if the route availability is based on a weight value that is assigned to each track member.`,
			},
			"weight_down": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The down weight assigned to the IP SLA Track List determines whether a route is considered available or unavailable. This attribute is applicable only when the track type is 'weight'.`,
			},
			"weight_up": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The up weight assigned to the IP SLA Track List determines whether a route is considered available or unavailable. The up weight must be greater than the down weight. This attribute is applicable only when the track type is 'weight'.`,
			},
			"relation_to_ip_sla_track_members": schema.SetNestedAttribute{
				MarkdownDescription: ``,
				Optional:            true,
				Computed:            true,
				PlanModifiers: []planmodifier.Set{
					setplanmodifier.UseStateForUnknown(),
					SetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate(FvRsOtmListMemberFvTrackListSetToSetNullWhenStateIsNullPlanIsUnknownDuringUpdate),
				},
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"annotation": schema.StringAttribute{
							Optional: true,
							Computed: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The annotation of the Relation To IP SLA Track Member object.`,
						},
						"target_dn": schema.StringAttribute{
							Required: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The distinguished name (DN) of the IP SLA Track Member.`,
						},
						"weight": schema.StringAttribute{
							Optional: true,
							Computed: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The weight associated with the IP SLA Track Member that contributes to the total weight that is used to determines whether a route is considered available or unavailable.`,
						},
						"annotations": schema.SetNestedAttribute{
							MarkdownDescription: ``,
							Optional:            true,
							Computed:            true,
							PlanModifiers: []planmodifier.Set{
								setplanmodifier.UseStateForUnknown(),
							},
							NestedObject: schema.NestedAttributeObject{
								Attributes: map[string]schema.Attribute{
									"key": schema.StringAttribute{
										Required: true,
										PlanModifiers: []planmodifier.String{
											stringplanmodifier.UseStateForUnknown(),
										},
										MarkdownDescription: `The key used to uniquely identify this configuration object.`,
									},
									"value": schema.StringAttribute{
										Required: true,
										PlanModifiers: []planmodifier.String{
											stringplanmodifier.UseStateForUnknown(),
										},
										MarkdownDescription: `The value of the property.`,
									},
								},
							},
						},
						"tags": schema.SetNestedAttribute{
							MarkdownDescription: ``,
							Optional:            true,
							Computed:            true,
							PlanModifiers: []planmodifier.Set{
								setplanmodifier.UseStateForUnknown(),
							},
							NestedObject: schema.NestedAttributeObject{
								Attributes: map[string]schema.Attribute{
									"key": schema.StringAttribute{
										Required: true,
										PlanModifiers: []planmodifier.String{
											stringplanmodifier.UseStateForUnknown(),
										},
										MarkdownDescription: `The key used to uniquely identify this configuration object.`,
									},
									"value": schema.StringAttribute{
										Required: true,
										PlanModifiers: []planmodifier.String{
											stringplanmodifier.UseStateForUnknown(),
										},
										MarkdownDescription: `The value of the property.`,
									},
								},
							},
						},
					},
				},
			},
			"annotations": schema.SetNestedAttribute{
				MarkdownDescription: ``,
				Optional:            true,
				Computed:            true,
				PlanModifiers: []planmodifier.Set{
					setplanmodifier.UseStateForUnknown(),
				},
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"key": schema.StringAttribute{
							Required: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The key used to uniquely identify this configuration object.`,
						},
						"value": schema.StringAttribute{
							Required: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The value of the property.`,
						},
					},
				},
			},
			"tags": schema.SetNestedAttribute{
				MarkdownDescription: ``,
				Optional:            true,
				Computed:            true,
				PlanModifiers: []planmodifier.Set{
					setplanmodifier.UseStateForUnknown(),
				},
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"key": schema.StringAttribute{
							Required: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The key used to uniquely identify this configuration object.`,
						},
						"value": schema.StringAttribute{
							Required: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The value of the property.`,
						},
					},
				},
			},
		},
	}
	tflog.Debug(ctx, "End schema of resource: aci_ip_sla_track_list")
}

func (r *FvTrackListResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
	tflog.Debug(ctx, "Start configure of resource: aci_ip_sla_track_list")
	// 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 Resource Configure Type",
			fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
		)

		return
	}

	r.client = client
	tflog.Debug(ctx, "End configure of resource: aci_ip_sla_track_list")
}

func (r *FvTrackListResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
	tflog.Debug(ctx, "Start create of resource: aci_ip_sla_track_list")
	// On create retrieve information on current state prior to making any changes in order to determine child delete operations
	var stateData *FvTrackListResourceModel
	resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...)
	if stateData.Id.IsUnknown() || stateData.Id.IsNull() {
		setFvTrackListId(ctx, stateData)
	}
	getAndSetFvTrackListAttributes(ctx, &resp.Diagnostics, r.client, stateData)
	if !globalAllowExistingOnCreate && !stateData.Id.IsNull() {
		resp.Diagnostics.AddError(
			"Object Already Exists",
			fmt.Sprintf("The fvTrackList object with DN '%s' already exists.", stateData.Id.ValueString()),
		)
		return
	}

	var data *FvTrackListResourceModel

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

	if resp.Diagnostics.HasError() {
		return
	}

	if data.Id.IsUnknown() || data.Id.IsNull() {
		setFvTrackListId(ctx, data)
	}

	tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_ip_sla_track_list with id '%s'", data.Id.ValueString()))

	var fvRsOtmListMemberPlan, fvRsOtmListMemberState []FvRsOtmListMemberFvTrackListResourceModel
	data.FvRsOtmListMember.ElementsAs(ctx, &fvRsOtmListMemberPlan, false)
	stateData.FvRsOtmListMember.ElementsAs(ctx, &fvRsOtmListMemberState, false)
	var tagAnnotationPlan, tagAnnotationState []TagAnnotationFvTrackListResourceModel
	data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false)
	stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false)
	var tagTagPlan, tagTagState []TagTagFvTrackListResourceModel
	data.TagTag.ElementsAs(ctx, &tagTagPlan, false)
	stateData.TagTag.ElementsAs(ctx, &tagTagState, false)
	jsonPayload := getFvTrackListCreateJsonPayload(ctx, &resp.Diagnostics, true, data, fvRsOtmListMemberPlan, fvRsOtmListMemberState, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState)

	if resp.Diagnostics.HasError() {
		return
	}

	DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)

	if resp.Diagnostics.HasError() {
		return
	}

	getAndSetFvTrackListAttributes(ctx, &resp.Diagnostics, r.client, data)

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

func (r *FvTrackListResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
	tflog.Debug(ctx, "Start read of resource: aci_ip_sla_track_list")
	var data *FvTrackListResourceModel

	// Read Terraform prior state data into the model
	resp.Diagnostics.Append(req.State.Get(ctx, &data)...)

	if resp.Diagnostics.HasError() {
		return
	}

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

	getAndSetFvTrackListAttributes(ctx, &resp.Diagnostics, r.client, data)

	// Save updated data into Terraform state
	if data.Id.IsNull() {
		var emptyData *FvTrackListResourceModel
		resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...)
	} else {
		resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
	}

	tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_ip_sla_track_list with id '%s'", data.Id.ValueString()))
}

func (r *FvTrackListResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
	tflog.Debug(ctx, "Start update of resource: aci_ip_sla_track_list")
	var data *FvTrackListResourceModel
	var stateData *FvTrackListResourceModel

	// Read Terraform plan data into the model
	resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
	resp.Diagnostics.Append(req.State.Get(ctx, &stateData)...)

	if resp.Diagnostics.HasError() {
		return
	}

	tflog.Debug(ctx, fmt.Sprintf("Update of resource aci_ip_sla_track_list with id '%s'", data.Id.ValueString()))

	var fvRsOtmListMemberPlan, fvRsOtmListMemberState []FvRsOtmListMemberFvTrackListResourceModel
	data.FvRsOtmListMember.ElementsAs(ctx, &fvRsOtmListMemberPlan, false)
	stateData.FvRsOtmListMember.ElementsAs(ctx, &fvRsOtmListMemberState, false)
	var tagAnnotationPlan, tagAnnotationState []TagAnnotationFvTrackListResourceModel
	data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false)
	stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false)
	var tagTagPlan, tagTagState []TagTagFvTrackListResourceModel
	data.TagTag.ElementsAs(ctx, &tagTagPlan, false)
	stateData.TagTag.ElementsAs(ctx, &tagTagState, false)
	jsonPayload := getFvTrackListCreateJsonPayload(ctx, &resp.Diagnostics, false, data, fvRsOtmListMemberPlan, fvRsOtmListMemberState, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState)

	if resp.Diagnostics.HasError() {
		return
	}

	DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)

	if resp.Diagnostics.HasError() {
		return
	}

	getAndSetFvTrackListAttributes(ctx, &resp.Diagnostics, r.client, data)

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

func (r *FvTrackListResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
	tflog.Debug(ctx, "Start delete of resource: aci_ip_sla_track_list")
	var data *FvTrackListResourceModel

	// Read Terraform prior state data into the model
	resp.Diagnostics.Append(req.State.Get(ctx, &data)...)

	if resp.Diagnostics.HasError() {
		return
	}

	tflog.Debug(ctx, fmt.Sprintf("Delete of resource aci_ip_sla_track_list with id '%s'", data.Id.ValueString()))
	jsonPayload := GetDeleteJsonPayload(ctx, &resp.Diagnostics, "fvTrackList", data.Id.ValueString())
	if resp.Diagnostics.HasError() {
		return
	}
	DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)
	if resp.Diagnostics.HasError() {
		return
	}
	tflog.Debug(ctx, fmt.Sprintf("End delete of resource aci_ip_sla_track_list with id '%s'", data.Id.ValueString()))
}

func (r *FvTrackListResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
	tflog.Debug(ctx, "Start import state of resource: aci_ip_sla_track_list")
	resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)

	var stateData *FvTrackListResourceModel
	resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...)
	tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_ip_sla_track_list with id '%s'", stateData.Id.ValueString()))

	tflog.Debug(ctx, "End import of state resource: aci_ip_sla_track_list")
}

func getAndSetFvTrackListAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvTrackListResourceModel) {
	requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvTrackList,fvRsOtmListMember,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil)

	readData := getEmptyFvTrackListResourceModel()

	if diags.HasError() {
		return
	}
	if requestData.Search("imdata").Search("fvTrackList").Data() != nil {
		classReadInfo := requestData.Search("imdata").Search("fvTrackList").Data().([]interface{})
		if len(classReadInfo) == 1 {
			attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{})
			for attributeName, attributeValue := range attributes {
				if attributeName == "dn" {
					readData.Id = basetypes.NewStringValue(attributeValue.(string))
					setFvTrackListParentDn(ctx, attributeValue.(string), readData)
				}
				if attributeName == "annotation" {
					readData.Annotation = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "descr" {
					readData.Descr = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "name" {
					readData.Name = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "nameAlias" {
					readData.NameAlias = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "ownerKey" {
					readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "ownerTag" {
					readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "percentageDown" {
					readData.PercentageDown = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "percentageUp" {
					readData.PercentageUp = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "type" {
					readData.Type = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "weightDown" {
					readData.WeightDown = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "weightUp" {
					readData.WeightUp = basetypes.NewStringValue(attributeValue.(string))
				}
			}
			FvRsOtmListMemberFvTrackListList := make([]FvRsOtmListMemberFvTrackListResourceModel, 0)
			TagAnnotationFvTrackListList := make([]TagAnnotationFvTrackListResourceModel, 0)
			TagTagFvTrackListList := make([]TagTagFvTrackListResourceModel, 0)
			_, ok := classReadInfo[0].(map[string]interface{})["children"]
			if ok {
				children := classReadInfo[0].(map[string]interface{})["children"].([]interface{})
				for _, child := range children {
					for childClassName, childClassDetails := range child.(map[string]interface{}) {
						childAttributes := childClassDetails.(map[string]interface{})["attributes"].(map[string]interface{})
						if childClassName == "fvRsOtmListMember" {
							FvRsOtmListMemberFvTrackList := getEmptyFvRsOtmListMemberFvTrackListResourceModel()
							for childAttributeName, childAttributeValue := range childAttributes {
								if childAttributeName == "annotation" {
									FvRsOtmListMemberFvTrackList.Annotation = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "tDn" {
									FvRsOtmListMemberFvTrackList.TDn = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "weight" {
									FvRsOtmListMemberFvTrackList.Weight = basetypes.NewStringValue(childAttributeValue.(string))
								}

							}
							TagAnnotationFvRsOtmListMemberFvTrackListList := make([]TagAnnotationFvRsOtmListMemberFvTrackListResourceModel, 0)
							TagTagFvRsOtmListMemberFvTrackListList := make([]TagTagFvRsOtmListMemberFvTrackListResourceModel, 0)
							childrenOfFvRsOtmListMemberFvTrackList, childrenOfFvRsOtmListMemberFvTrackListExist := childClassDetails.(map[string]interface{})["children"]
							if childrenOfFvRsOtmListMemberFvTrackListExist {
								for _, childFvRsOtmListMemberFvTrackList := range childrenOfFvRsOtmListMemberFvTrackList.([]interface{}) {
									for childClassNameFvRsOtmListMemberFvTrackList, childClassDetailsFvRsOtmListMemberFvTrackList := range childFvRsOtmListMemberFvTrackList.(map[string]interface{}) {
										if childClassNameFvRsOtmListMemberFvTrackList == "tagAnnotation" {
											TagAnnotationFvRsOtmListMemberFvTrackList := getEmptyTagAnnotationFvRsOtmListMemberFvTrackListResourceModel()
											tagAnnotationchildAttributeValue := childClassDetailsFvRsOtmListMemberFvTrackList.(map[string]interface{})["attributes"].(map[string]interface{})
											for childAttributeName, childAttributeValue := range tagAnnotationchildAttributeValue {
												if childAttributeName == "key" {
													TagAnnotationFvRsOtmListMemberFvTrackList.Key = basetypes.NewStringValue(childAttributeValue.(string))
												}
												if childAttributeName == "value" {
													TagAnnotationFvRsOtmListMemberFvTrackList.Value = basetypes.NewStringValue(childAttributeValue.(string))
												}
											}
											TagAnnotationFvRsOtmListMemberFvTrackListList = append(TagAnnotationFvRsOtmListMemberFvTrackListList, TagAnnotationFvRsOtmListMemberFvTrackList)
										}
										if childClassNameFvRsOtmListMemberFvTrackList == "tagTag" {
											TagTagFvRsOtmListMemberFvTrackList := getEmptyTagTagFvRsOtmListMemberFvTrackListResourceModel()
											tagTagchildAttributeValue := childClassDetailsFvRsOtmListMemberFvTrackList.(map[string]interface{})["attributes"].(map[string]interface{})
											for childAttributeName, childAttributeValue := range tagTagchildAttributeValue {
												if childAttributeName == "key" {
													TagTagFvRsOtmListMemberFvTrackList.Key = basetypes.NewStringValue(childAttributeValue.(string))
												}
												if childAttributeName == "value" {
													TagTagFvRsOtmListMemberFvTrackList.Value = basetypes.NewStringValue(childAttributeValue.(string))
												}
											}
											TagTagFvRsOtmListMemberFvTrackListList = append(TagTagFvRsOtmListMemberFvTrackListList, TagTagFvRsOtmListMemberFvTrackList)
										}
									}
								}
							}
							TagAnnotationFvRsOtmListMemberFvTrackListSet, _ := types.SetValueFrom(ctx, TagAnnotationFvRsOtmListMemberFvTrackListType, TagAnnotationFvRsOtmListMemberFvTrackListList)
							FvRsOtmListMemberFvTrackList.TagAnnotation = TagAnnotationFvRsOtmListMemberFvTrackListSet
							TagTagFvRsOtmListMemberFvTrackListSet, _ := types.SetValueFrom(ctx, TagTagFvRsOtmListMemberFvTrackListType, TagTagFvRsOtmListMemberFvTrackListList)
							FvRsOtmListMemberFvTrackList.TagTag = TagTagFvRsOtmListMemberFvTrackListSet
							FvRsOtmListMemberFvTrackListList = append(FvRsOtmListMemberFvTrackListList, FvRsOtmListMemberFvTrackList)
						}
						if childClassName == "tagAnnotation" {
							TagAnnotationFvTrackList := getEmptyTagAnnotationFvTrackListResourceModel()
							for childAttributeName, childAttributeValue := range childAttributes {
								if childAttributeName == "key" {
									TagAnnotationFvTrackList.Key = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "value" {
									TagAnnotationFvTrackList.Value = basetypes.NewStringValue(childAttributeValue.(string))
								}

							}
							TagAnnotationFvTrackListList = append(TagAnnotationFvTrackListList, TagAnnotationFvTrackList)
						}
						if childClassName == "tagTag" {
							TagTagFvTrackList := getEmptyTagTagFvTrackListResourceModel()
							for childAttributeName, childAttributeValue := range childAttributes {
								if childAttributeName == "key" {
									TagTagFvTrackList.Key = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "value" {
									TagTagFvTrackList.Value = basetypes.NewStringValue(childAttributeValue.(string))
								}

							}
							TagTagFvTrackListList = append(TagTagFvTrackListList, TagTagFvTrackList)
						}
					}
				}
			}
			fvRsOtmListMemberSet, _ := types.SetValueFrom(ctx, readData.FvRsOtmListMember.ElementType(ctx), FvRsOtmListMemberFvTrackListList)
			readData.FvRsOtmListMember = fvRsOtmListMemberSet
			tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvTrackListList)
			readData.TagAnnotation = tagAnnotationSet
			tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvTrackListList)
			readData.TagTag = tagTagSet
		} else {
			diags.AddError(
				"too many results in response",
				fmt.Sprintf("%v matches returned for class 'fvTrackList'. Please report this issue to the provider developers.", len(classReadInfo)),
			)
		}
	} else {
		readData.Id = basetypes.NewStringNull()
	}
	*data = *readData
}

func getFvTrackListRn(ctx context.Context, data *FvTrackListResourceModel) string {
	return fmt.Sprintf("tracklist-%s", data.Name.ValueString())
}

func setFvTrackListParentDn(ctx context.Context, dn string, data *FvTrackListResourceModel) {
	bracketIndex := 0
	rnIndex := 0
	for i := len(dn) - 1; i >= 0; i-- {
		if string(dn[i]) == "]" {
			bracketIndex = bracketIndex + 1
		} else if string(dn[i]) == "[" {
			bracketIndex = bracketIndex - 1
		} else if string(dn[i]) == "/" && bracketIndex == 0 {
			rnIndex = i
			break
		}
	}
	data.ParentDn = basetypes.NewStringValue(dn[:rnIndex])
}

func setFvTrackListId(ctx context.Context, data *FvTrackListResourceModel) {
	rn := getFvTrackListRn(ctx, data)
	data.Id = types.StringValue(fmt.Sprintf("%s/%s", data.ParentDn.ValueString(), rn))
}

func getFvTrackListFvRsOtmListMemberChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *FvTrackListResourceModel, fvRsOtmListMemberFvTrackListPlan, fvRsOtmListMemberFvTrackListState []FvRsOtmListMemberFvTrackListResourceModel) []map[string]interface{} {
	childPayloads := []map[string]interface{}{}
	if !data.FvRsOtmListMember.IsNull() && !data.FvRsOtmListMember.IsUnknown() {
		fvRsOtmListMemberIdentifiers := []FvRsOtmListMemberIdentifier{}
		for _, fvRsOtmListMemberFvTrackList := range fvRsOtmListMemberFvTrackListPlan {
			FvRsOtmListMemberFvTrackListChildren := make([]map[string]interface{}, 0)
			childMap := NewAciObject()
			if !fvRsOtmListMemberFvTrackList.Annotation.IsNull() && !fvRsOtmListMemberFvTrackList.Annotation.IsUnknown() {
				childMap.Attributes["annotation"] = fvRsOtmListMemberFvTrackList.Annotation.ValueString()
			} else {
				childMap.Attributes["annotation"] = globalAnnotation
			}
			if !fvRsOtmListMemberFvTrackList.TDn.IsNull() && !fvRsOtmListMemberFvTrackList.TDn.IsUnknown() {
				childMap.Attributes["tDn"] = fvRsOtmListMemberFvTrackList.TDn.ValueString()
			}
			if !fvRsOtmListMemberFvTrackList.Weight.IsNull() && !fvRsOtmListMemberFvTrackList.Weight.IsUnknown() {
				childMap.Attributes["weight"] = fvRsOtmListMemberFvTrackList.Weight.ValueString()
			}

			var tagAnnotationFvRsOtmListMemberFvTrackListPlan, tagAnnotationFvRsOtmListMemberFvTrackListState []TagAnnotationFvRsOtmListMemberFvTrackListResourceModel
			fvRsOtmListMemberFvTrackList.TagAnnotation.ElementsAs(ctx, &tagAnnotationFvRsOtmListMemberFvTrackListPlan, false)
			for _, tagAnnotationFvRsOtmListMemberFvTrackListstate := range fvRsOtmListMemberFvTrackListState {
				tagAnnotationFvRsOtmListMemberFvTrackListstate.TagAnnotation.ElementsAs(ctx, &tagAnnotationFvRsOtmListMemberFvTrackListState, false)
			}
			if !fvRsOtmListMemberFvTrackList.TagAnnotation.IsNull() && !fvRsOtmListMemberFvTrackList.TagAnnotation.IsUnknown() {
				tagAnnotationIdentifiers := []TagAnnotationIdentifier{}
				for _, tagAnnotationFvRsOtmListMemberFvTrackList := range tagAnnotationFvRsOtmListMemberFvTrackListPlan {
					tagAnnotationFvRsOtmListMemberFvTrackListChildMap := NewAciObject()
					if !tagAnnotationFvRsOtmListMemberFvTrackList.Key.IsNull() && !tagAnnotationFvRsOtmListMemberFvTrackList.Key.IsUnknown() {
						tagAnnotationFvRsOtmListMemberFvTrackListChildMap.Attributes["key"] = tagAnnotationFvRsOtmListMemberFvTrackList.Key.ValueString()
					}
					if !tagAnnotationFvRsOtmListMemberFvTrackList.Value.IsNull() && !tagAnnotationFvRsOtmListMemberFvTrackList.Value.IsUnknown() {
						tagAnnotationFvRsOtmListMemberFvTrackListChildMap.Attributes["value"] = tagAnnotationFvRsOtmListMemberFvTrackList.Value.ValueString()
					}
					FvRsOtmListMemberFvTrackListChildren = append(FvRsOtmListMemberFvTrackListChildren, map[string]interface{}{"tagAnnotation": tagAnnotationFvRsOtmListMemberFvTrackListChildMap})
					tagAnnotationIdentifier := TagAnnotationIdentifier{}
					tagAnnotationIdentifier.Key = tagAnnotationFvRsOtmListMemberFvTrackList.Key
					tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier)
				}
				for _, tagAnnotationFvRsOtmListMemberFvTrackList := range tagAnnotationFvRsOtmListMemberFvTrackListState {
					delete := true
					for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers {
						if tagAnnotationIdentifier.Key == tagAnnotationFvRsOtmListMemberFvTrackList.Key {
							delete = false
							break
						}
					}
					if delete {
						tagAnnotationFvRsOtmListMemberFvTrackListChildMapForDelete := NewAciObject()
						tagAnnotationFvRsOtmListMemberFvTrackListChildMapForDelete.Attributes["status"] = "deleted"
						tagAnnotationFvRsOtmListMemberFvTrackListChildMapForDelete.Attributes["key"] = tagAnnotationFvRsOtmListMemberFvTrackList.Key.ValueString()
						FvRsOtmListMemberFvTrackListChildren = append(FvRsOtmListMemberFvTrackListChildren, map[string]interface{}{"tagAnnotation": tagAnnotationFvRsOtmListMemberFvTrackListChildMapForDelete})
					}
				}
			}

			var tagTagFvRsOtmListMemberFvTrackListPlan, tagTagFvRsOtmListMemberFvTrackListState []TagTagFvRsOtmListMemberFvTrackListResourceModel
			fvRsOtmListMemberFvTrackList.TagTag.ElementsAs(ctx, &tagTagFvRsOtmListMemberFvTrackListPlan, false)
			for _, tagTagFvRsOtmListMemberFvTrackListstate := range fvRsOtmListMemberFvTrackListState {
				tagTagFvRsOtmListMemberFvTrackListstate.TagTag.ElementsAs(ctx, &tagTagFvRsOtmListMemberFvTrackListState, false)
			}
			if !fvRsOtmListMemberFvTrackList.TagTag.IsNull() && !fvRsOtmListMemberFvTrackList.TagTag.IsUnknown() {
				tagTagIdentifiers := []TagTagIdentifier{}
				for _, tagTagFvRsOtmListMemberFvTrackList := range tagTagFvRsOtmListMemberFvTrackListPlan {
					tagTagFvRsOtmListMemberFvTrackListChildMap := NewAciObject()
					if !tagTagFvRsOtmListMemberFvTrackList.Key.IsNull() && !tagTagFvRsOtmListMemberFvTrackList.Key.IsUnknown() {
						tagTagFvRsOtmListMemberFvTrackListChildMap.Attributes["key"] = tagTagFvRsOtmListMemberFvTrackList.Key.ValueString()
					}
					if !tagTagFvRsOtmListMemberFvTrackList.Value.IsNull() && !tagTagFvRsOtmListMemberFvTrackList.Value.IsUnknown() {
						tagTagFvRsOtmListMemberFvTrackListChildMap.Attributes["value"] = tagTagFvRsOtmListMemberFvTrackList.Value.ValueString()
					}
					FvRsOtmListMemberFvTrackListChildren = append(FvRsOtmListMemberFvTrackListChildren, map[string]interface{}{"tagTag": tagTagFvRsOtmListMemberFvTrackListChildMap})
					tagTagIdentifier := TagTagIdentifier{}
					tagTagIdentifier.Key = tagTagFvRsOtmListMemberFvTrackList.Key
					tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier)
				}
				for _, tagTagFvRsOtmListMemberFvTrackList := range tagTagFvRsOtmListMemberFvTrackListState {
					delete := true
					for _, tagTagIdentifier := range tagTagIdentifiers {
						if tagTagIdentifier.Key == tagTagFvRsOtmListMemberFvTrackList.Key {
							delete = false
							break
						}
					}
					if delete {
						tagTagFvRsOtmListMemberFvTrackListChildMapForDelete := NewAciObject()
						tagTagFvRsOtmListMemberFvTrackListChildMapForDelete.Attributes["status"] = "deleted"
						tagTagFvRsOtmListMemberFvTrackListChildMapForDelete.Attributes["key"] = tagTagFvRsOtmListMemberFvTrackList.Key.ValueString()
						FvRsOtmListMemberFvTrackListChildren = append(FvRsOtmListMemberFvTrackListChildren, map[string]interface{}{"tagTag": tagTagFvRsOtmListMemberFvTrackListChildMapForDelete})
					}
				}
			}
			childMap.Children = FvRsOtmListMemberFvTrackListChildren
			childPayloads = append(childPayloads, map[string]interface{}{"fvRsOtmListMember": childMap})
			fvRsOtmListMemberIdentifier := FvRsOtmListMemberIdentifier{}
			fvRsOtmListMemberIdentifier.TDn = fvRsOtmListMemberFvTrackList.TDn
			fvRsOtmListMemberIdentifiers = append(fvRsOtmListMemberIdentifiers, fvRsOtmListMemberIdentifier)
		}
		for _, fvRsOtmListMember := range fvRsOtmListMemberFvTrackListState {
			delete := true
			for _, fvRsOtmListMemberIdentifier := range fvRsOtmListMemberIdentifiers {
				if fvRsOtmListMemberIdentifier.TDn == fvRsOtmListMember.TDn {
					delete = false
					break
				}
			}
			if delete {
				fvRsOtmListMemberChildMapForDelete := NewAciObject()
				fvRsOtmListMemberChildMapForDelete.Attributes["status"] = "deleted"
				fvRsOtmListMemberChildMapForDelete.Attributes["tDn"] = fvRsOtmListMember.TDn.ValueString()
				childPayloads = append(childPayloads, map[string]interface{}{"fvRsOtmListMember": fvRsOtmListMemberChildMapForDelete})
			}
		}
	} else {
		data.FvRsOtmListMember = types.SetNull(data.FvRsOtmListMember.ElementType(ctx))
	}

	return childPayloads
}

func getFvTrackListTagAnnotationChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *FvTrackListResourceModel, tagAnnotationFvTrackListPlan, tagAnnotationFvTrackListState []TagAnnotationFvTrackListResourceModel) []map[string]interface{} {
	childPayloads := []map[string]interface{}{}
	if !data.TagAnnotation.IsNull() && !data.TagAnnotation.IsUnknown() {
		tagAnnotationIdentifiers := []TagAnnotationIdentifier{}
		for _, tagAnnotationFvTrackList := range tagAnnotationFvTrackListPlan {
			childMap := NewAciObject()
			if !tagAnnotationFvTrackList.Key.IsNull() && !tagAnnotationFvTrackList.Key.IsUnknown() {
				childMap.Attributes["key"] = tagAnnotationFvTrackList.Key.ValueString()
			}
			if !tagAnnotationFvTrackList.Value.IsNull() && !tagAnnotationFvTrackList.Value.IsUnknown() {
				childMap.Attributes["value"] = tagAnnotationFvTrackList.Value.ValueString()
			}
			childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap})
			tagAnnotationIdentifier := TagAnnotationIdentifier{}
			tagAnnotationIdentifier.Key = tagAnnotationFvTrackList.Key
			tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier)
		}
		for _, tagAnnotation := range tagAnnotationFvTrackListState {
			delete := true
			for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers {
				if tagAnnotationIdentifier.Key == tagAnnotation.Key {
					delete = false
					break
				}
			}
			if delete {
				tagAnnotationChildMapForDelete := NewAciObject()
				tagAnnotationChildMapForDelete.Attributes["status"] = "deleted"
				tagAnnotationChildMapForDelete.Attributes["key"] = tagAnnotation.Key.ValueString()
				childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": tagAnnotationChildMapForDelete})
			}
		}
	} else {
		data.TagAnnotation = types.SetNull(data.TagAnnotation.ElementType(ctx))
	}

	return childPayloads
}

func getFvTrackListTagTagChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *FvTrackListResourceModel, tagTagFvTrackListPlan, tagTagFvTrackListState []TagTagFvTrackListResourceModel) []map[string]interface{} {
	childPayloads := []map[string]interface{}{}
	if !data.TagTag.IsNull() && !data.TagTag.IsUnknown() {
		tagTagIdentifiers := []TagTagIdentifier{}
		for _, tagTagFvTrackList := range tagTagFvTrackListPlan {
			childMap := NewAciObject()
			if !tagTagFvTrackList.Key.IsNull() && !tagTagFvTrackList.Key.IsUnknown() {
				childMap.Attributes["key"] = tagTagFvTrackList.Key.ValueString()
			}
			if !tagTagFvTrackList.Value.IsNull() && !tagTagFvTrackList.Value.IsUnknown() {
				childMap.Attributes["value"] = tagTagFvTrackList.Value.ValueString()
			}
			childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap})
			tagTagIdentifier := TagTagIdentifier{}
			tagTagIdentifier.Key = tagTagFvTrackList.Key
			tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier)
		}
		for _, tagTag := range tagTagFvTrackListState {
			delete := true
			for _, tagTagIdentifier := range tagTagIdentifiers {
				if tagTagIdentifier.Key == tagTag.Key {
					delete = false
					break
				}
			}
			if delete {
				tagTagChildMapForDelete := NewAciObject()
				tagTagChildMapForDelete.Attributes["status"] = "deleted"
				tagTagChildMapForDelete.Attributes["key"] = tagTag.Key.ValueString()
				childPayloads = append(childPayloads, map[string]interface{}{"tagTag": tagTagChildMapForDelete})
			}
		}
	} else {
		data.TagTag = types.SetNull(data.TagTag.ElementType(ctx))
	}

	return childPayloads
}

func getFvTrackListCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, createType bool, data *FvTrackListResourceModel, fvRsOtmListMemberPlan, fvRsOtmListMemberState []FvRsOtmListMemberFvTrackListResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationFvTrackListResourceModel, tagTagPlan, tagTagState []TagTagFvTrackListResourceModel) *container.Container {
	payloadMap := map[string]interface{}{}
	payloadMap["attributes"] = map[string]string{}

	if createType && !globalAllowExistingOnCreate {
		payloadMap["attributes"].(map[string]string)["status"] = "created"
	}
	childPayloads := []map[string]interface{}{}

	FvRsOtmListMemberchildPayloads := getFvTrackListFvRsOtmListMemberChildPayloads(ctx, diags, data, fvRsOtmListMemberPlan, fvRsOtmListMemberState)
	if FvRsOtmListMemberchildPayloads == nil {
		return nil
	}
	childPayloads = append(childPayloads, FvRsOtmListMemberchildPayloads...)

	TagAnnotationchildPayloads := getFvTrackListTagAnnotationChildPayloads(ctx, diags, data, tagAnnotationPlan, tagAnnotationState)
	if TagAnnotationchildPayloads == nil {
		return nil
	}
	childPayloads = append(childPayloads, TagAnnotationchildPayloads...)

	TagTagchildPayloads := getFvTrackListTagTagChildPayloads(ctx, diags, data, tagTagPlan, tagTagState)
	if TagTagchildPayloads == nil {
		return nil
	}
	childPayloads = append(childPayloads, TagTagchildPayloads...)

	payloadMap["children"] = childPayloads
	if !data.Annotation.IsNull() && !data.Annotation.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["annotation"] = data.Annotation.ValueString()
	}
	if !data.Descr.IsNull() && !data.Descr.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["descr"] = data.Descr.ValueString()
	}
	if !data.Name.IsNull() && !data.Name.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["name"] = data.Name.ValueString()
	}
	if !data.NameAlias.IsNull() && !data.NameAlias.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["nameAlias"] = data.NameAlias.ValueString()
	}
	if !data.OwnerKey.IsNull() && !data.OwnerKey.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["ownerKey"] = data.OwnerKey.ValueString()
	}
	if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString()
	}
	if !data.PercentageDown.IsNull() && !data.PercentageDown.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["percentageDown"] = data.PercentageDown.ValueString()
	}
	if !data.PercentageUp.IsNull() && !data.PercentageUp.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["percentageUp"] = data.PercentageUp.ValueString()
	}
	if !data.Type.IsNull() && !data.Type.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["type"] = data.Type.ValueString()
	}
	if !data.WeightDown.IsNull() && !data.WeightDown.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["weightDown"] = data.WeightDown.ValueString()
	}
	if !data.WeightUp.IsNull() && !data.WeightUp.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["weightUp"] = data.WeightUp.ValueString()
	}
	payload, err := json.Marshal(map[string]interface{}{"fvTrackList": payloadMap})
	if err != nil {
		diags.AddError(
			"Marshalling of json payload failed",
			fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err),
		)
		return nil
	}

	jsonPayload, err := container.ParseJSON(payload)

	if err != nil {
		diags.AddError(
			"Construction of json payload failed",
			fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err),
		)
		return nil
	}
	return jsonPayload
}
