// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Mozilla Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://mozilla.org/MPL/2.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: MPL-2.0

// Code generated by "gen/generator.go"; DO NOT EDIT.

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
	"context"
	"fmt"
	"net/url"
	"reflect"
	"regexp"
	"strconv"
	"strings"

	"github.com/CiscoDevNet/terraform-provider-iosxe/internal/provider/helpers"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/tidwall/gjson"
	"github.com/tidwall/sjson"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin types
type StaticRoutesVRF struct {
	Device types.String            `tfsdk:"device"`
	Id     types.String            `tfsdk:"id"`
	Vrf    types.String            `tfsdk:"vrf"`
	Routes []StaticRoutesVRFRoutes `tfsdk:"routes"`
}

type StaticRoutesVRFData struct {
	Device types.String            `tfsdk:"device"`
	Id     types.String            `tfsdk:"id"`
	Vrf    types.String            `tfsdk:"vrf"`
	Routes []StaticRoutesVRFRoutes `tfsdk:"routes"`
}
type StaticRoutesVRFRoutes struct {
	Prefix            types.String                             `tfsdk:"prefix"`
	Mask              types.String                             `tfsdk:"mask"`
	NextHops          []StaticRoutesVRFRoutesNextHops          `tfsdk:"next_hops"`
	NextHopsWithTrack []StaticRoutesVRFRoutesNextHopsWithTrack `tfsdk:"next_hops_with_track"`
}
type StaticRoutesVRFRoutesNextHops struct {
	NextHop   types.String `tfsdk:"next_hop"`
	Distance  types.Int64  `tfsdk:"distance"`
	Global    types.Bool   `tfsdk:"global"`
	Name      types.String `tfsdk:"name"`
	Permanent types.Bool   `tfsdk:"permanent"`
	Tag       types.Int64  `tfsdk:"tag"`
}
type StaticRoutesVRFRoutesNextHopsWithTrack struct {
	NextHop     types.String `tfsdk:"next_hop"`
	Name        types.String `tfsdk:"name"`
	TrackIdName types.Int64  `tfsdk:"track_id_name"`
	Distance    types.Int64  `tfsdk:"distance"`
	Tag         types.Int64  `tfsdk:"tag"`
	Permanent   types.Bool   `tfsdk:"permanent"`
}

// End of section. //template:end types

// Section below is generated&owned by "gen/generator.go". //template:begin getPath

func (data StaticRoutesVRF) getPath() string {
	return fmt.Sprintf("Cisco-IOS-XE-native:native/ip/route/vrf=%s", url.QueryEscape(fmt.Sprintf("%v", data.Vrf.ValueString())))
}

func (data StaticRoutesVRFData) getPath() string {
	return fmt.Sprintf("Cisco-IOS-XE-native:native/ip/route/vrf=%s", url.QueryEscape(fmt.Sprintf("%v", data.Vrf.ValueString())))
}

// if last path element has a key -> remove it
func (data StaticRoutesVRF) getPathShort() string {
	path := data.getPath()
	re := regexp.MustCompile(`(.*)=[^\/]*$`)
	matches := re.FindStringSubmatch(path)
	if len(matches) <= 1 {
		return path
	}
	return matches[1]
}

// End of section. //template:end getPath

// Section below is generated&owned by "gen/generator.go". //template:begin toBody

func (data StaticRoutesVRF) toBody(ctx context.Context) string {
	body := `{"` + helpers.LastElement(data.getPath()) + `":{}}`
	if !data.Vrf.IsNull() && !data.Vrf.IsUnknown() {
		body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"name", data.Vrf.ValueString())
	}
	if len(data.Routes) > 0 {
		body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list", []interface{}{})
		for index, item := range data.Routes {
			if !item.Prefix.IsNull() && !item.Prefix.IsUnknown() {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"prefix", item.Prefix.ValueString())
			}
			if !item.Mask.IsNull() && !item.Mask.IsUnknown() {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"mask", item.Mask.ValueString())
			}
			if len(item.NextHops) > 0 {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list", []interface{}{})
				for cindex, citem := range item.NextHops {
					if !citem.NextHop.IsNull() && !citem.NextHop.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list"+"."+strconv.Itoa(cindex)+"."+"fwd", citem.NextHop.ValueString())
					}
					if !citem.Distance.IsNull() && !citem.Distance.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list"+"."+strconv.Itoa(cindex)+"."+"metric", strconv.FormatInt(citem.Distance.ValueInt64(), 10))
					}
					if !citem.Global.IsNull() && !citem.Global.IsUnknown() {
						if citem.Global.ValueBool() {
							body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list"+"."+strconv.Itoa(cindex)+"."+"global", map[string]string{})
						}
					}
					if !citem.Name.IsNull() && !citem.Name.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list"+"."+strconv.Itoa(cindex)+"."+"name", citem.Name.ValueString())
					}
					if !citem.Permanent.IsNull() && !citem.Permanent.IsUnknown() {
						if citem.Permanent.ValueBool() {
							body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list"+"."+strconv.Itoa(cindex)+"."+"permanent", map[string]string{})
						}
					}
					if !citem.Tag.IsNull() && !citem.Tag.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list"+"."+strconv.Itoa(cindex)+"."+"tag", strconv.FormatInt(citem.Tag.ValueInt64(), 10))
					}
				}
			}
			if len(item.NextHopsWithTrack) > 0 {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list-with-track", []interface{}{})
				for cindex, citem := range item.NextHopsWithTrack {
					if !citem.NextHop.IsNull() && !citem.NextHop.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list-with-track"+"."+strconv.Itoa(cindex)+"."+"fwd", citem.NextHop.ValueString())
					}
					if !citem.Name.IsNull() && !citem.Name.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list-with-track"+"."+strconv.Itoa(cindex)+"."+"name", citem.Name.ValueString())
					}
					if !citem.TrackIdName.IsNull() && !citem.TrackIdName.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list-with-track"+"."+strconv.Itoa(cindex)+"."+"track-id-name.id", strconv.FormatInt(citem.TrackIdName.ValueInt64(), 10))
					}
					if !citem.Distance.IsNull() && !citem.Distance.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list-with-track"+"."+strconv.Itoa(cindex)+"."+"metric", strconv.FormatInt(citem.Distance.ValueInt64(), 10))
					}
					if !citem.Tag.IsNull() && !citem.Tag.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list-with-track"+"."+strconv.Itoa(cindex)+"."+"tag", strconv.FormatInt(citem.Tag.ValueInt64(), 10))
					}
					if !citem.Permanent.IsNull() && !citem.Permanent.IsUnknown() {
						if citem.Permanent.ValueBool() {
							body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"ip-route-interface-forwarding-list"+"."+strconv.Itoa(index)+"."+"fwd-list-with-track"+"."+strconv.Itoa(cindex)+"."+"permanent", map[string]string{})
						}
					}
				}
			}
		}
	}
	return body
}

// End of section. //template:end toBody

// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody

func (data *StaticRoutesVRF) updateFromBody(ctx context.Context, res gjson.Result) {
	prefix := helpers.LastElement(data.getPath()) + "."
	if res.Get(helpers.LastElement(data.getPath())).IsArray() {
		prefix += "0."
	}
	if value := res.Get(prefix + "name"); value.Exists() && !data.Vrf.IsNull() {
		data.Vrf = types.StringValue(value.String())
	} else {
		data.Vrf = types.StringNull()
	}
	for i := range data.Routes {
		keys := [...]string{"prefix", "mask"}
		keyValues := [...]string{data.Routes[i].Prefix.ValueString(), data.Routes[i].Mask.ValueString()}

		var r gjson.Result
		res.Get(prefix + "ip-route-interface-forwarding-list").ForEach(
			func(_, v gjson.Result) bool {
				found := false
				for ik := range keys {
					if v.Get(keys[ik]).String() == keyValues[ik] {
						found = true
						continue
					}
					found = false
					break
				}
				if found {
					r = v
					return false
				}
				return true
			},
		)
		if value := r.Get("prefix"); value.Exists() && !data.Routes[i].Prefix.IsNull() {
			data.Routes[i].Prefix = types.StringValue(value.String())
		} else {
			data.Routes[i].Prefix = types.StringNull()
		}
		if value := r.Get("mask"); value.Exists() && !data.Routes[i].Mask.IsNull() {
			data.Routes[i].Mask = types.StringValue(value.String())
		} else {
			data.Routes[i].Mask = types.StringNull()
		}
		for ci := range data.Routes[i].NextHops {
			keys := [...]string{"fwd"}
			keyValues := [...]string{data.Routes[i].NextHops[ci].NextHop.ValueString()}

			var cr gjson.Result
			r.Get("fwd-list").ForEach(
				func(_, v gjson.Result) bool {
					found := false
					for ik := range keys {
						if v.Get(keys[ik]).String() == keyValues[ik] {
							found = true
							continue
						}
						found = false
						break
					}
					if found {
						cr = v
						return false
					}
					return true
				},
			)
			if value := cr.Get("fwd"); value.Exists() && !data.Routes[i].NextHops[ci].NextHop.IsNull() {
				data.Routes[i].NextHops[ci].NextHop = types.StringValue(value.String())
			} else {
				data.Routes[i].NextHops[ci].NextHop = types.StringNull()
			}
			if value := cr.Get("metric"); value.Exists() && !data.Routes[i].NextHops[ci].Distance.IsNull() {
				data.Routes[i].NextHops[ci].Distance = types.Int64Value(value.Int())
			} else {
				data.Routes[i].NextHops[ci].Distance = types.Int64Null()
			}
			if value := cr.Get("global"); !data.Routes[i].NextHops[ci].Global.IsNull() {
				if value.Exists() {
					data.Routes[i].NextHops[ci].Global = types.BoolValue(true)
				} else {
					data.Routes[i].NextHops[ci].Global = types.BoolValue(false)
				}
			} else {
				data.Routes[i].NextHops[ci].Global = types.BoolNull()
			}
			if value := cr.Get("name"); value.Exists() && !data.Routes[i].NextHops[ci].Name.IsNull() {
				data.Routes[i].NextHops[ci].Name = types.StringValue(value.String())
			} else {
				data.Routes[i].NextHops[ci].Name = types.StringNull()
			}
			if value := cr.Get("permanent"); !data.Routes[i].NextHops[ci].Permanent.IsNull() {
				if value.Exists() {
					data.Routes[i].NextHops[ci].Permanent = types.BoolValue(true)
				} else {
					data.Routes[i].NextHops[ci].Permanent = types.BoolValue(false)
				}
			} else {
				data.Routes[i].NextHops[ci].Permanent = types.BoolNull()
			}
			if value := cr.Get("tag"); value.Exists() && !data.Routes[i].NextHops[ci].Tag.IsNull() {
				data.Routes[i].NextHops[ci].Tag = types.Int64Value(value.Int())
			} else {
				data.Routes[i].NextHops[ci].Tag = types.Int64Null()
			}
		}
		for ci := range data.Routes[i].NextHopsWithTrack {
			keys := [...]string{"fwd"}
			keyValues := [...]string{data.Routes[i].NextHopsWithTrack[ci].NextHop.ValueString()}

			var cr gjson.Result
			r.Get("fwd-list-with-track").ForEach(
				func(_, v gjson.Result) bool {
					found := false
					for ik := range keys {
						if v.Get(keys[ik]).String() == keyValues[ik] {
							found = true
							continue
						}
						found = false
						break
					}
					if found {
						cr = v
						return false
					}
					return true
				},
			)
			if value := cr.Get("fwd"); value.Exists() && !data.Routes[i].NextHopsWithTrack[ci].NextHop.IsNull() {
				data.Routes[i].NextHopsWithTrack[ci].NextHop = types.StringValue(value.String())
			} else {
				data.Routes[i].NextHopsWithTrack[ci].NextHop = types.StringNull()
			}
			if value := cr.Get("name"); value.Exists() && !data.Routes[i].NextHopsWithTrack[ci].Name.IsNull() {
				data.Routes[i].NextHopsWithTrack[ci].Name = types.StringValue(value.String())
			} else {
				data.Routes[i].NextHopsWithTrack[ci].Name = types.StringNull()
			}
			if value := cr.Get("track-id-name.id"); value.Exists() && !data.Routes[i].NextHopsWithTrack[ci].TrackIdName.IsNull() {
				data.Routes[i].NextHopsWithTrack[ci].TrackIdName = types.Int64Value(value.Int())
			} else {
				data.Routes[i].NextHopsWithTrack[ci].TrackIdName = types.Int64Null()
			}
			if value := cr.Get("metric"); value.Exists() && !data.Routes[i].NextHopsWithTrack[ci].Distance.IsNull() {
				data.Routes[i].NextHopsWithTrack[ci].Distance = types.Int64Value(value.Int())
			} else {
				data.Routes[i].NextHopsWithTrack[ci].Distance = types.Int64Null()
			}
			if value := cr.Get("tag"); value.Exists() && !data.Routes[i].NextHopsWithTrack[ci].Tag.IsNull() {
				data.Routes[i].NextHopsWithTrack[ci].Tag = types.Int64Value(value.Int())
			} else {
				data.Routes[i].NextHopsWithTrack[ci].Tag = types.Int64Null()
			}
			if value := cr.Get("permanent"); !data.Routes[i].NextHopsWithTrack[ci].Permanent.IsNull() {
				if value.Exists() {
					data.Routes[i].NextHopsWithTrack[ci].Permanent = types.BoolValue(true)
				} else {
					data.Routes[i].NextHopsWithTrack[ci].Permanent = types.BoolValue(false)
				}
			} else {
				data.Routes[i].NextHopsWithTrack[ci].Permanent = types.BoolNull()
			}
		}
	}
}

// End of section. //template:end updateFromBody

// Section below is generated&owned by "gen/generator.go". //template:begin fromBody

func (data *StaticRoutesVRF) fromBody(ctx context.Context, res gjson.Result) {
	prefix := helpers.LastElement(data.getPath()) + "."
	if res.Get(helpers.LastElement(data.getPath())).IsArray() {
		prefix += "0."
	}
	if value := res.Get(prefix + "ip-route-interface-forwarding-list"); value.Exists() {
		data.Routes = make([]StaticRoutesVRFRoutes, 0)
		value.ForEach(func(k, v gjson.Result) bool {
			item := StaticRoutesVRFRoutes{}
			if cValue := v.Get("prefix"); cValue.Exists() {
				item.Prefix = types.StringValue(cValue.String())
			}
			if cValue := v.Get("mask"); cValue.Exists() {
				item.Mask = types.StringValue(cValue.String())
			}
			if cValue := v.Get("fwd-list"); cValue.Exists() {
				item.NextHops = make([]StaticRoutesVRFRoutesNextHops, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := StaticRoutesVRFRoutesNextHops{}
					if ccValue := cv.Get("fwd"); ccValue.Exists() {
						cItem.NextHop = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("metric"); ccValue.Exists() {
						cItem.Distance = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("global"); ccValue.Exists() {
						cItem.Global = types.BoolValue(true)
					} else {
						cItem.Global = types.BoolValue(false)
					}
					if ccValue := cv.Get("name"); ccValue.Exists() {
						cItem.Name = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("permanent"); ccValue.Exists() {
						cItem.Permanent = types.BoolValue(true)
					} else {
						cItem.Permanent = types.BoolValue(false)
					}
					if ccValue := cv.Get("tag"); ccValue.Exists() {
						cItem.Tag = types.Int64Value(ccValue.Int())
					}
					item.NextHops = append(item.NextHops, cItem)
					return true
				})
			}
			if cValue := v.Get("fwd-list-with-track"); cValue.Exists() {
				item.NextHopsWithTrack = make([]StaticRoutesVRFRoutesNextHopsWithTrack, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := StaticRoutesVRFRoutesNextHopsWithTrack{}
					if ccValue := cv.Get("fwd"); ccValue.Exists() {
						cItem.NextHop = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("name"); ccValue.Exists() {
						cItem.Name = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("track-id-name.id"); ccValue.Exists() {
						cItem.TrackIdName = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("metric"); ccValue.Exists() {
						cItem.Distance = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("tag"); ccValue.Exists() {
						cItem.Tag = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("permanent"); ccValue.Exists() {
						cItem.Permanent = types.BoolValue(true)
					} else {
						cItem.Permanent = types.BoolValue(false)
					}
					item.NextHopsWithTrack = append(item.NextHopsWithTrack, cItem)
					return true
				})
			}
			data.Routes = append(data.Routes, item)
			return true
		})
	}
}

// End of section. //template:end fromBody

// Section below is generated&owned by "gen/generator.go". //template:begin fromBodyData

func (data *StaticRoutesVRFData) fromBody(ctx context.Context, res gjson.Result) {
	prefix := helpers.LastElement(data.getPath()) + "."
	if res.Get(helpers.LastElement(data.getPath())).IsArray() {
		prefix += "0."
	}
	if value := res.Get(prefix + "ip-route-interface-forwarding-list"); value.Exists() {
		data.Routes = make([]StaticRoutesVRFRoutes, 0)
		value.ForEach(func(k, v gjson.Result) bool {
			item := StaticRoutesVRFRoutes{}
			if cValue := v.Get("prefix"); cValue.Exists() {
				item.Prefix = types.StringValue(cValue.String())
			}
			if cValue := v.Get("mask"); cValue.Exists() {
				item.Mask = types.StringValue(cValue.String())
			}
			if cValue := v.Get("fwd-list"); cValue.Exists() {
				item.NextHops = make([]StaticRoutesVRFRoutesNextHops, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := StaticRoutesVRFRoutesNextHops{}
					if ccValue := cv.Get("fwd"); ccValue.Exists() {
						cItem.NextHop = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("metric"); ccValue.Exists() {
						cItem.Distance = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("global"); ccValue.Exists() {
						cItem.Global = types.BoolValue(true)
					} else {
						cItem.Global = types.BoolValue(false)
					}
					if ccValue := cv.Get("name"); ccValue.Exists() {
						cItem.Name = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("permanent"); ccValue.Exists() {
						cItem.Permanent = types.BoolValue(true)
					} else {
						cItem.Permanent = types.BoolValue(false)
					}
					if ccValue := cv.Get("tag"); ccValue.Exists() {
						cItem.Tag = types.Int64Value(ccValue.Int())
					}
					item.NextHops = append(item.NextHops, cItem)
					return true
				})
			}
			if cValue := v.Get("fwd-list-with-track"); cValue.Exists() {
				item.NextHopsWithTrack = make([]StaticRoutesVRFRoutesNextHopsWithTrack, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := StaticRoutesVRFRoutesNextHopsWithTrack{}
					if ccValue := cv.Get("fwd"); ccValue.Exists() {
						cItem.NextHop = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("name"); ccValue.Exists() {
						cItem.Name = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("track-id-name.id"); ccValue.Exists() {
						cItem.TrackIdName = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("metric"); ccValue.Exists() {
						cItem.Distance = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("tag"); ccValue.Exists() {
						cItem.Tag = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("permanent"); ccValue.Exists() {
						cItem.Permanent = types.BoolValue(true)
					} else {
						cItem.Permanent = types.BoolValue(false)
					}
					item.NextHopsWithTrack = append(item.NextHopsWithTrack, cItem)
					return true
				})
			}
			data.Routes = append(data.Routes, item)
			return true
		})
	}
}

// End of section. //template:end fromBodyData

// Section below is generated&owned by "gen/generator.go". //template:begin getDeletedItems

func (data *StaticRoutesVRF) getDeletedItems(ctx context.Context, state StaticRoutesVRF) []string {
	deletedItems := make([]string, 0)
	for i := range state.Routes {
		stateKeyValues := [...]string{state.Routes[i].Prefix.ValueString(), state.Routes[i].Mask.ValueString()}

		emptyKeys := true
		if !reflect.ValueOf(state.Routes[i].Prefix.ValueString()).IsZero() {
			emptyKeys = false
		}
		if !reflect.ValueOf(state.Routes[i].Mask.ValueString()).IsZero() {
			emptyKeys = false
		}
		if emptyKeys {
			continue
		}

		found := false
		for j := range data.Routes {
			found = true
			if state.Routes[i].Prefix.ValueString() != data.Routes[j].Prefix.ValueString() {
				found = false
			}
			if state.Routes[i].Mask.ValueString() != data.Routes[j].Mask.ValueString() {
				found = false
			}
			if found {
				for ci := range state.Routes[i].NextHopsWithTrack {
					cstateKeyValues := [...]string{state.Routes[i].NextHopsWithTrack[ci].NextHop.ValueString()}

					cemptyKeys := true
					if !reflect.ValueOf(state.Routes[i].NextHopsWithTrack[ci].NextHop.ValueString()).IsZero() {
						cemptyKeys = false
					}
					if cemptyKeys {
						continue
					}

					found := false
					for cj := range data.Routes[j].NextHopsWithTrack {
						found = true
						if state.Routes[i].NextHopsWithTrack[ci].NextHop.ValueString() != data.Routes[j].NextHopsWithTrack[cj].NextHop.ValueString() {
							found = false
						}
						if found {
							if !state.Routes[i].NextHopsWithTrack[ci].Permanent.IsNull() && data.Routes[j].NextHopsWithTrack[cj].Permanent.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list-with-track=%v/permanent", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Routes[i].NextHopsWithTrack[ci].Tag.IsNull() && data.Routes[j].NextHopsWithTrack[cj].Tag.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list-with-track=%v/tag", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Routes[i].NextHopsWithTrack[ci].Distance.IsNull() && data.Routes[j].NextHopsWithTrack[cj].Distance.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list-with-track=%v/metric", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Routes[i].NextHopsWithTrack[ci].TrackIdName.IsNull() && data.Routes[j].NextHopsWithTrack[cj].TrackIdName.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list-with-track=%v/track-id-name/id", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Routes[i].NextHopsWithTrack[ci].Name.IsNull() && data.Routes[j].NextHopsWithTrack[cj].Name.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list-with-track=%v/name", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							break
						}
					}
					if !found {
						deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list-with-track=%v", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
					}
				}
				for ci := range state.Routes[i].NextHops {
					cstateKeyValues := [...]string{state.Routes[i].NextHops[ci].NextHop.ValueString()}

					cemptyKeys := true
					if !reflect.ValueOf(state.Routes[i].NextHops[ci].NextHop.ValueString()).IsZero() {
						cemptyKeys = false
					}
					if cemptyKeys {
						continue
					}

					found := false
					for cj := range data.Routes[j].NextHops {
						found = true
						if state.Routes[i].NextHops[ci].NextHop.ValueString() != data.Routes[j].NextHops[cj].NextHop.ValueString() {
							found = false
						}
						if found {
							if !state.Routes[i].NextHops[ci].Tag.IsNull() && data.Routes[j].NextHops[cj].Tag.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list=%v/tag", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Routes[i].NextHops[ci].Permanent.IsNull() && data.Routes[j].NextHops[cj].Permanent.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list=%v/permanent", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Routes[i].NextHops[ci].Name.IsNull() && data.Routes[j].NextHops[cj].Name.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list=%v/name", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Routes[i].NextHops[ci].Global.IsNull() && data.Routes[j].NextHops[cj].Global.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list=%v/global", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Routes[i].NextHops[ci].Distance.IsNull() && data.Routes[j].NextHops[cj].Distance.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list=%v/metric", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							break
						}
					}
					if !found {
						deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list=%v", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
					}
				}
				break
			}
		}
		if !found {
			deletedItems = append(deletedItems, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v", state.getPath(), strings.Join(stateKeyValues[:], ",")))
		}
	}

	return deletedItems
}

// End of section. //template:end getDeletedItems

// Section below is generated&owned by "gen/generator.go". //template:begin getEmptyLeafsDelete

func (data *StaticRoutesVRF) getEmptyLeafsDelete(ctx context.Context) []string {
	emptyLeafsDelete := make([]string, 0)

	for i := range data.Routes {
		keyValues := [...]string{data.Routes[i].Prefix.ValueString(), data.Routes[i].Mask.ValueString()}

		for ci := range data.Routes[i].NextHopsWithTrack {
			ckeyValues := [...]string{data.Routes[i].NextHopsWithTrack[ci].NextHop.ValueString()}
			if !data.Routes[i].NextHopsWithTrack[ci].Permanent.IsNull() && !data.Routes[i].NextHopsWithTrack[ci].Permanent.ValueBool() {
				emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list-with-track=%v/permanent", data.getPath(), strings.Join(keyValues[:], ","), strings.Join(ckeyValues[:], ",")))
			}
		}

		for ci := range data.Routes[i].NextHops {
			ckeyValues := [...]string{data.Routes[i].NextHops[ci].NextHop.ValueString()}
			if !data.Routes[i].NextHops[ci].Permanent.IsNull() && !data.Routes[i].NextHops[ci].Permanent.ValueBool() {
				emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list=%v/permanent", data.getPath(), strings.Join(keyValues[:], ","), strings.Join(ckeyValues[:], ",")))
			}
			if !data.Routes[i].NextHops[ci].Global.IsNull() && !data.Routes[i].NextHops[ci].Global.ValueBool() {
				emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v/fwd-list=%v/global", data.getPath(), strings.Join(keyValues[:], ","), strings.Join(ckeyValues[:], ",")))
			}
		}
	}

	return emptyLeafsDelete
}

// End of section. //template:end getEmptyLeafsDelete

// Section below is generated&owned by "gen/generator.go". //template:begin getDeletePaths

func (data *StaticRoutesVRF) getDeletePaths(ctx context.Context) []string {
	var deletePaths []string
	for i := range data.Routes {
		keyValues := [...]string{data.Routes[i].Prefix.ValueString(), data.Routes[i].Mask.ValueString()}

		deletePaths = append(deletePaths, fmt.Sprintf("%v/ip-route-interface-forwarding-list=%v", data.getPath(), strings.Join(keyValues[:], ",")))
	}

	return deletePaths
}

// End of section. //template:end getDeletePaths
