// 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 BGPAddressFamilyIPv4VRF struct {
	Device     types.String                  `tfsdk:"device"`
	Id         types.String                  `tfsdk:"id"`
	DeleteMode types.String                  `tfsdk:"delete_mode"`
	Asn        types.String                  `tfsdk:"asn"`
	AfName     types.String                  `tfsdk:"af_name"`
	Vrfs       []BGPAddressFamilyIPv4VRFVrfs `tfsdk:"vrfs"`
}

type BGPAddressFamilyIPv4VRFData struct {
	Device types.String                  `tfsdk:"device"`
	Id     types.String                  `tfsdk:"id"`
	Asn    types.String                  `tfsdk:"asn"`
	AfName types.String                  `tfsdk:"af_name"`
	Vrfs   []BGPAddressFamilyIPv4VRFVrfs `tfsdk:"vrfs"`
}
type BGPAddressFamilyIPv4VRFVrfs struct {
	Name                             types.String                                               `tfsdk:"name"`
	Ipv4UnicastAdvertiseL2vpnEvpn    types.Bool                                                 `tfsdk:"ipv4_unicast_advertise_l2vpn_evpn"`
	Ipv4UnicastRedistributeConnected types.Bool                                                 `tfsdk:"ipv4_unicast_redistribute_connected"`
	Ipv4UnicastRouterIdLoopback      types.Int64                                                `tfsdk:"ipv4_unicast_router_id_loopback"`
	Ipv4UnicastAggregateAddresses    []BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAggregateAddresses `tfsdk:"ipv4_unicast_aggregate_addresses"`
	Ipv4UnicastRedistributeStatic    types.Bool                                                 `tfsdk:"ipv4_unicast_redistribute_static"`
	Ipv4UnicastNetworksMask          []BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworksMask       `tfsdk:"ipv4_unicast_networks_mask"`
	Ipv4UnicastNetworks              []BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworks           `tfsdk:"ipv4_unicast_networks"`
	Ipv4UnicastAdminDistances        []BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAdminDistances     `tfsdk:"ipv4_unicast_admin_distances"`
	Ipv4UnicastDistanceBgpExternal   types.Int64                                                `tfsdk:"ipv4_unicast_distance_bgp_external"`
	Ipv4UnicastDistanceBgpInternal   types.Int64                                                `tfsdk:"ipv4_unicast_distance_bgp_internal"`
	Ipv4UnicastDistanceBgpLocal      types.Int64                                                `tfsdk:"ipv4_unicast_distance_bgp_local"`
}
type BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAggregateAddresses struct {
	Ipv4Address types.String `tfsdk:"ipv4_address"`
	Ipv4Mask    types.String `tfsdk:"ipv4_mask"`
}
type BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworksMask struct {
	Network  types.String `tfsdk:"network"`
	Mask     types.String `tfsdk:"mask"`
	RouteMap types.String `tfsdk:"route_map"`
	Backdoor types.Bool   `tfsdk:"backdoor"`
	Evpn     types.Bool   `tfsdk:"evpn"`
}
type BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworks struct {
	Network  types.String `tfsdk:"network"`
	RouteMap types.String `tfsdk:"route_map"`
	Backdoor types.Bool   `tfsdk:"backdoor"`
	Evpn     types.Bool   `tfsdk:"evpn"`
}
type BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAdminDistances struct {
	Distance types.Int64  `tfsdk:"distance"`
	SourceIp types.String `tfsdk:"source_ip"`
	Wildcard types.String `tfsdk:"wildcard"`
	Acl      types.String `tfsdk:"acl"`
}

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

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

func (data BGPAddressFamilyIPv4VRF) getPath() string {
	return fmt.Sprintf("Cisco-IOS-XE-native:native/router/Cisco-IOS-XE-bgp:bgp=%v/address-family/with-vrf/ipv4=%s", url.QueryEscape(fmt.Sprintf("%v", data.Asn.ValueString())), url.QueryEscape(fmt.Sprintf("%v", data.AfName.ValueString())))
}

func (data BGPAddressFamilyIPv4VRFData) getPath() string {
	return fmt.Sprintf("Cisco-IOS-XE-native:native/router/Cisco-IOS-XE-bgp:bgp=%v/address-family/with-vrf/ipv4=%s", url.QueryEscape(fmt.Sprintf("%v", data.Asn.ValueString())), url.QueryEscape(fmt.Sprintf("%v", data.AfName.ValueString())))
}

// if last path element has a key -> remove it
func (data BGPAddressFamilyIPv4VRF) 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 BGPAddressFamilyIPv4VRF) toBody(ctx context.Context) string {
	body := `{"` + helpers.LastElement(data.getPath()) + `":{}}`
	if !data.AfName.IsNull() && !data.AfName.IsUnknown() {
		body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"af-name", data.AfName.ValueString())
	}
	if len(data.Vrfs) > 0 {
		body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf", []interface{}{})
		for index, item := range data.Vrfs {
			if !item.Name.IsNull() && !item.Name.IsUnknown() {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"name", item.Name.ValueString())
			}
			if !item.Ipv4UnicastAdvertiseL2vpnEvpn.IsNull() && !item.Ipv4UnicastAdvertiseL2vpnEvpn.IsUnknown() {
				if item.Ipv4UnicastAdvertiseL2vpnEvpn.ValueBool() {
					body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.advertise.l2vpn.evpn", map[string]string{})
				}
			}
			if !item.Ipv4UnicastRedistributeConnected.IsNull() && !item.Ipv4UnicastRedistributeConnected.IsUnknown() {
				if item.Ipv4UnicastRedistributeConnected.ValueBool() {
					body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.redistribute-vrf.connected", map[string]string{})
				}
			}
			if !item.Ipv4UnicastRouterIdLoopback.IsNull() && !item.Ipv4UnicastRouterIdLoopback.IsUnknown() {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.bgp.router-id.interface.Loopback", strconv.FormatInt(item.Ipv4UnicastRouterIdLoopback.ValueInt64(), 10))
			}
			if !item.Ipv4UnicastRedistributeStatic.IsNull() && !item.Ipv4UnicastRedistributeStatic.IsUnknown() {
				if item.Ipv4UnicastRedistributeStatic.ValueBool() {
					body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.redistribute-vrf.static", map[string]string{})
				}
			}
			if !item.Ipv4UnicastDistanceBgpExternal.IsNull() && !item.Ipv4UnicastDistanceBgpExternal.IsUnknown() {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.distance.bgp.extern-as", strconv.FormatInt(item.Ipv4UnicastDistanceBgpExternal.ValueInt64(), 10))
			}
			if !item.Ipv4UnicastDistanceBgpInternal.IsNull() && !item.Ipv4UnicastDistanceBgpInternal.IsUnknown() {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.distance.bgp.internal-as", strconv.FormatInt(item.Ipv4UnicastDistanceBgpInternal.ValueInt64(), 10))
			}
			if !item.Ipv4UnicastDistanceBgpLocal.IsNull() && !item.Ipv4UnicastDistanceBgpLocal.IsUnknown() {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.distance.bgp.local", strconv.FormatInt(item.Ipv4UnicastDistanceBgpLocal.ValueInt64(), 10))
			}
			if len(item.Ipv4UnicastAggregateAddresses) > 0 {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.aggregate-address", []interface{}{})
				for cindex, citem := range item.Ipv4UnicastAggregateAddresses {
					if !citem.Ipv4Address.IsNull() && !citem.Ipv4Address.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.aggregate-address"+"."+strconv.Itoa(cindex)+"."+"ipv4-address", citem.Ipv4Address.ValueString())
					}
					if !citem.Ipv4Mask.IsNull() && !citem.Ipv4Mask.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.aggregate-address"+"."+strconv.Itoa(cindex)+"."+"ipv4-mask", citem.Ipv4Mask.ValueString())
					}
				}
			}
			if len(item.Ipv4UnicastNetworksMask) > 0 {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.with-mask", []interface{}{})
				for cindex, citem := range item.Ipv4UnicastNetworksMask {
					if !citem.Network.IsNull() && !citem.Network.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.with-mask"+"."+strconv.Itoa(cindex)+"."+"number", citem.Network.ValueString())
					}
					if !citem.Mask.IsNull() && !citem.Mask.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.with-mask"+"."+strconv.Itoa(cindex)+"."+"mask", citem.Mask.ValueString())
					}
					if !citem.RouteMap.IsNull() && !citem.RouteMap.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.with-mask"+"."+strconv.Itoa(cindex)+"."+"route-map", citem.RouteMap.ValueString())
					}
					if !citem.Backdoor.IsNull() && !citem.Backdoor.IsUnknown() {
						if citem.Backdoor.ValueBool() {
							body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.with-mask"+"."+strconv.Itoa(cindex)+"."+"backdoor", map[string]string{})
						}
					}
					if !citem.Evpn.IsNull() && !citem.Evpn.IsUnknown() {
						if citem.Evpn.ValueBool() {
							body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.with-mask"+"."+strconv.Itoa(cindex)+"."+"evpn", map[string]string{})
						}
					}
				}
			}
			if len(item.Ipv4UnicastNetworks) > 0 {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.no-mask", []interface{}{})
				for cindex, citem := range item.Ipv4UnicastNetworks {
					if !citem.Network.IsNull() && !citem.Network.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.no-mask"+"."+strconv.Itoa(cindex)+"."+"number", citem.Network.ValueString())
					}
					if !citem.RouteMap.IsNull() && !citem.RouteMap.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.no-mask"+"."+strconv.Itoa(cindex)+"."+"route-map", citem.RouteMap.ValueString())
					}
					if !citem.Backdoor.IsNull() && !citem.Backdoor.IsUnknown() {
						if citem.Backdoor.ValueBool() {
							body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.no-mask"+"."+strconv.Itoa(cindex)+"."+"backdoor", map[string]string{})
						}
					}
					if !citem.Evpn.IsNull() && !citem.Evpn.IsUnknown() {
						if citem.Evpn.ValueBool() {
							body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.network.no-mask"+"."+strconv.Itoa(cindex)+"."+"evpn", map[string]string{})
						}
					}
				}
			}
			if len(item.Ipv4UnicastAdminDistances) > 0 {
				body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.distance.adm-distance", []interface{}{})
				for cindex, citem := range item.Ipv4UnicastAdminDistances {
					if !citem.Distance.IsNull() && !citem.Distance.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.distance.adm-distance"+"."+strconv.Itoa(cindex)+"."+"distance", strconv.FormatInt(citem.Distance.ValueInt64(), 10))
					}
					if !citem.SourceIp.IsNull() && !citem.SourceIp.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.distance.adm-distance"+"."+strconv.Itoa(cindex)+"."+"srcip", citem.SourceIp.ValueString())
					}
					if !citem.Wildcard.IsNull() && !citem.Wildcard.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.distance.adm-distance"+"."+strconv.Itoa(cindex)+"."+"wildbits", citem.Wildcard.ValueString())
					}
					if !citem.Acl.IsNull() && !citem.Acl.IsUnknown() {
						body, _ = sjson.Set(body, helpers.LastElement(data.getPath())+"."+"vrf"+"."+strconv.Itoa(index)+"."+"ipv4-unicast.distance.adm-distance"+"."+strconv.Itoa(cindex)+"."+"acl", citem.Acl.ValueString())
					}
				}
			}
		}
	}
	return body
}

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

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

func (data *BGPAddressFamilyIPv4VRF) 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 + "af-name"); value.Exists() && !data.AfName.IsNull() {
		data.AfName = types.StringValue(value.String())
	} else {
		data.AfName = types.StringNull()
	}
	for i := range data.Vrfs {
		keys := [...]string{"name"}
		keyValues := [...]string{data.Vrfs[i].Name.ValueString()}

		var r gjson.Result
		res.Get(prefix + "vrf").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("name"); value.Exists() && !data.Vrfs[i].Name.IsNull() {
			data.Vrfs[i].Name = types.StringValue(value.String())
		} else {
			data.Vrfs[i].Name = types.StringNull()
		}
		if value := r.Get("ipv4-unicast.advertise.l2vpn.evpn"); !data.Vrfs[i].Ipv4UnicastAdvertiseL2vpnEvpn.IsNull() {
			if value.Exists() {
				data.Vrfs[i].Ipv4UnicastAdvertiseL2vpnEvpn = types.BoolValue(true)
			} else {
				data.Vrfs[i].Ipv4UnicastAdvertiseL2vpnEvpn = types.BoolValue(false)
			}
		} else {
			data.Vrfs[i].Ipv4UnicastAdvertiseL2vpnEvpn = types.BoolNull()
		}
		if value := r.Get("ipv4-unicast.redistribute-vrf.connected"); !data.Vrfs[i].Ipv4UnicastRedistributeConnected.IsNull() {
			if value.Exists() {
				data.Vrfs[i].Ipv4UnicastRedistributeConnected = types.BoolValue(true)
			} else {
				data.Vrfs[i].Ipv4UnicastRedistributeConnected = types.BoolValue(false)
			}
		} else {
			data.Vrfs[i].Ipv4UnicastRedistributeConnected = types.BoolNull()
		}
		if value := r.Get("ipv4-unicast.bgp.router-id.interface.Loopback"); value.Exists() && !data.Vrfs[i].Ipv4UnicastRouterIdLoopback.IsNull() {
			data.Vrfs[i].Ipv4UnicastRouterIdLoopback = types.Int64Value(value.Int())
		} else {
			data.Vrfs[i].Ipv4UnicastRouterIdLoopback = types.Int64Null()
		}
		for ci := range data.Vrfs[i].Ipv4UnicastAggregateAddresses {
			keys := [...]string{"ipv4-address", "ipv4-mask"}
			keyValues := [...]string{data.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Address.ValueString(), data.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Mask.ValueString()}

			var cr gjson.Result
			r.Get("ipv4-unicast.aggregate-address").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("ipv4-address"); value.Exists() && !data.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Address.IsNull() {
				data.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Address = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Address = types.StringNull()
			}
			if value := cr.Get("ipv4-mask"); value.Exists() && !data.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Mask.IsNull() {
				data.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Mask = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Mask = types.StringNull()
			}
		}
		if value := r.Get("ipv4-unicast.redistribute-vrf.static"); !data.Vrfs[i].Ipv4UnicastRedistributeStatic.IsNull() {
			if value.Exists() {
				data.Vrfs[i].Ipv4UnicastRedistributeStatic = types.BoolValue(true)
			} else {
				data.Vrfs[i].Ipv4UnicastRedistributeStatic = types.BoolValue(false)
			}
		} else {
			data.Vrfs[i].Ipv4UnicastRedistributeStatic = types.BoolNull()
		}
		for ci := range data.Vrfs[i].Ipv4UnicastNetworksMask {
			keys := [...]string{"number", "mask"}
			keyValues := [...]string{data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Network.ValueString(), data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Mask.ValueString()}

			var cr gjson.Result
			r.Get("ipv4-unicast.network.with-mask").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("number"); value.Exists() && !data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Network.IsNull() {
				data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Network = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Network = types.StringNull()
			}
			if value := cr.Get("mask"); value.Exists() && !data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Mask.IsNull() {
				data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Mask = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Mask = types.StringNull()
			}
			if value := cr.Get("route-map"); value.Exists() && !data.Vrfs[i].Ipv4UnicastNetworksMask[ci].RouteMap.IsNull() {
				data.Vrfs[i].Ipv4UnicastNetworksMask[ci].RouteMap = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastNetworksMask[ci].RouteMap = types.StringNull()
			}
			if value := cr.Get("backdoor"); !data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Backdoor.IsNull() {
				if value.Exists() {
					data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Backdoor = types.BoolValue(true)
				} else {
					data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Backdoor = types.BoolValue(false)
				}
			} else {
				data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Backdoor = types.BoolNull()
			}
			if value := cr.Get("evpn"); !data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Evpn.IsNull() {
				if value.Exists() {
					data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Evpn = types.BoolValue(true)
				} else {
					data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Evpn = types.BoolValue(false)
				}
			} else {
				data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Evpn = types.BoolNull()
			}
		}
		for ci := range data.Vrfs[i].Ipv4UnicastNetworks {
			keys := [...]string{"number"}
			keyValues := [...]string{data.Vrfs[i].Ipv4UnicastNetworks[ci].Network.ValueString()}

			var cr gjson.Result
			r.Get("ipv4-unicast.network.no-mask").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("number"); value.Exists() && !data.Vrfs[i].Ipv4UnicastNetworks[ci].Network.IsNull() {
				data.Vrfs[i].Ipv4UnicastNetworks[ci].Network = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastNetworks[ci].Network = types.StringNull()
			}
			if value := cr.Get("route-map"); value.Exists() && !data.Vrfs[i].Ipv4UnicastNetworks[ci].RouteMap.IsNull() {
				data.Vrfs[i].Ipv4UnicastNetworks[ci].RouteMap = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastNetworks[ci].RouteMap = types.StringNull()
			}
			if value := cr.Get("backdoor"); !data.Vrfs[i].Ipv4UnicastNetworks[ci].Backdoor.IsNull() {
				if value.Exists() {
					data.Vrfs[i].Ipv4UnicastNetworks[ci].Backdoor = types.BoolValue(true)
				} else {
					data.Vrfs[i].Ipv4UnicastNetworks[ci].Backdoor = types.BoolValue(false)
				}
			} else {
				data.Vrfs[i].Ipv4UnicastNetworks[ci].Backdoor = types.BoolNull()
			}
			if value := cr.Get("evpn"); !data.Vrfs[i].Ipv4UnicastNetworks[ci].Evpn.IsNull() {
				if value.Exists() {
					data.Vrfs[i].Ipv4UnicastNetworks[ci].Evpn = types.BoolValue(true)
				} else {
					data.Vrfs[i].Ipv4UnicastNetworks[ci].Evpn = types.BoolValue(false)
				}
			} else {
				data.Vrfs[i].Ipv4UnicastNetworks[ci].Evpn = types.BoolNull()
			}
		}
		for ci := range data.Vrfs[i].Ipv4UnicastAdminDistances {
			keys := [...]string{"distance", "srcip", "wildbits"}
			keyValues := [...]string{strconv.FormatInt(data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Distance.ValueInt64(), 10), data.Vrfs[i].Ipv4UnicastAdminDistances[ci].SourceIp.ValueString(), data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Wildcard.ValueString()}

			var cr gjson.Result
			r.Get("ipv4-unicast.distance.adm-distance").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("distance"); value.Exists() && !data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Distance.IsNull() {
				data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Distance = types.Int64Value(value.Int())
			} else {
				data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Distance = types.Int64Null()
			}
			if value := cr.Get("srcip"); value.Exists() && !data.Vrfs[i].Ipv4UnicastAdminDistances[ci].SourceIp.IsNull() {
				data.Vrfs[i].Ipv4UnicastAdminDistances[ci].SourceIp = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastAdminDistances[ci].SourceIp = types.StringNull()
			}
			if value := cr.Get("wildbits"); value.Exists() && !data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Wildcard.IsNull() {
				data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Wildcard = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Wildcard = types.StringNull()
			}
			if value := cr.Get("acl"); value.Exists() && !data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Acl.IsNull() {
				data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Acl = types.StringValue(value.String())
			} else {
				data.Vrfs[i].Ipv4UnicastAdminDistances[ci].Acl = types.StringNull()
			}
		}
		if value := r.Get("ipv4-unicast.distance.bgp.extern-as"); value.Exists() && !data.Vrfs[i].Ipv4UnicastDistanceBgpExternal.IsNull() {
			data.Vrfs[i].Ipv4UnicastDistanceBgpExternal = types.Int64Value(value.Int())
		} else {
			data.Vrfs[i].Ipv4UnicastDistanceBgpExternal = types.Int64Null()
		}
		if value := r.Get("ipv4-unicast.distance.bgp.internal-as"); value.Exists() && !data.Vrfs[i].Ipv4UnicastDistanceBgpInternal.IsNull() {
			data.Vrfs[i].Ipv4UnicastDistanceBgpInternal = types.Int64Value(value.Int())
		} else {
			data.Vrfs[i].Ipv4UnicastDistanceBgpInternal = types.Int64Null()
		}
		if value := r.Get("ipv4-unicast.distance.bgp.local"); value.Exists() && !data.Vrfs[i].Ipv4UnicastDistanceBgpLocal.IsNull() {
			data.Vrfs[i].Ipv4UnicastDistanceBgpLocal = types.Int64Value(value.Int())
		} else {
			data.Vrfs[i].Ipv4UnicastDistanceBgpLocal = types.Int64Null()
		}
	}
}

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

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

func (data *BGPAddressFamilyIPv4VRF) 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 + "vrf"); value.Exists() {
		data.Vrfs = make([]BGPAddressFamilyIPv4VRFVrfs, 0)
		value.ForEach(func(k, v gjson.Result) bool {
			item := BGPAddressFamilyIPv4VRFVrfs{}
			if cValue := v.Get("name"); cValue.Exists() {
				item.Name = types.StringValue(cValue.String())
			}
			if cValue := v.Get("ipv4-unicast.advertise.l2vpn.evpn"); cValue.Exists() {
				item.Ipv4UnicastAdvertiseL2vpnEvpn = types.BoolValue(true)
			} else {
				item.Ipv4UnicastAdvertiseL2vpnEvpn = types.BoolValue(false)
			}
			if cValue := v.Get("ipv4-unicast.redistribute-vrf.connected"); cValue.Exists() {
				item.Ipv4UnicastRedistributeConnected = types.BoolValue(true)
			} else {
				item.Ipv4UnicastRedistributeConnected = types.BoolValue(false)
			}
			if cValue := v.Get("ipv4-unicast.bgp.router-id.interface.Loopback"); cValue.Exists() {
				item.Ipv4UnicastRouterIdLoopback = types.Int64Value(cValue.Int())
			}
			if cValue := v.Get("ipv4-unicast.aggregate-address"); cValue.Exists() {
				item.Ipv4UnicastAggregateAddresses = make([]BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAggregateAddresses, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAggregateAddresses{}
					if ccValue := cv.Get("ipv4-address"); ccValue.Exists() {
						cItem.Ipv4Address = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("ipv4-mask"); ccValue.Exists() {
						cItem.Ipv4Mask = types.StringValue(ccValue.String())
					}
					item.Ipv4UnicastAggregateAddresses = append(item.Ipv4UnicastAggregateAddresses, cItem)
					return true
				})
			}
			if cValue := v.Get("ipv4-unicast.redistribute-vrf.static"); cValue.Exists() {
				item.Ipv4UnicastRedistributeStatic = types.BoolValue(true)
			} else {
				item.Ipv4UnicastRedistributeStatic = types.BoolValue(false)
			}
			if cValue := v.Get("ipv4-unicast.network.with-mask"); cValue.Exists() {
				item.Ipv4UnicastNetworksMask = make([]BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworksMask, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworksMask{}
					if ccValue := cv.Get("number"); ccValue.Exists() {
						cItem.Network = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("mask"); ccValue.Exists() {
						cItem.Mask = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("route-map"); ccValue.Exists() {
						cItem.RouteMap = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("backdoor"); ccValue.Exists() {
						cItem.Backdoor = types.BoolValue(true)
					} else {
						cItem.Backdoor = types.BoolValue(false)
					}
					if ccValue := cv.Get("evpn"); ccValue.Exists() {
						cItem.Evpn = types.BoolValue(true)
					} else {
						cItem.Evpn = types.BoolValue(false)
					}
					item.Ipv4UnicastNetworksMask = append(item.Ipv4UnicastNetworksMask, cItem)
					return true
				})
			}
			if cValue := v.Get("ipv4-unicast.network.no-mask"); cValue.Exists() {
				item.Ipv4UnicastNetworks = make([]BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworks, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworks{}
					if ccValue := cv.Get("number"); ccValue.Exists() {
						cItem.Network = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("route-map"); ccValue.Exists() {
						cItem.RouteMap = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("backdoor"); ccValue.Exists() {
						cItem.Backdoor = types.BoolValue(true)
					} else {
						cItem.Backdoor = types.BoolValue(false)
					}
					if ccValue := cv.Get("evpn"); ccValue.Exists() {
						cItem.Evpn = types.BoolValue(true)
					} else {
						cItem.Evpn = types.BoolValue(false)
					}
					item.Ipv4UnicastNetworks = append(item.Ipv4UnicastNetworks, cItem)
					return true
				})
			}
			if cValue := v.Get("ipv4-unicast.distance.adm-distance"); cValue.Exists() {
				item.Ipv4UnicastAdminDistances = make([]BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAdminDistances, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAdminDistances{}
					if ccValue := cv.Get("distance"); ccValue.Exists() {
						cItem.Distance = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("srcip"); ccValue.Exists() {
						cItem.SourceIp = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("wildbits"); ccValue.Exists() {
						cItem.Wildcard = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("acl"); ccValue.Exists() {
						cItem.Acl = types.StringValue(ccValue.String())
					}
					item.Ipv4UnicastAdminDistances = append(item.Ipv4UnicastAdminDistances, cItem)
					return true
				})
			}
			if cValue := v.Get("ipv4-unicast.distance.bgp.extern-as"); cValue.Exists() {
				item.Ipv4UnicastDistanceBgpExternal = types.Int64Value(cValue.Int())
			}
			if cValue := v.Get("ipv4-unicast.distance.bgp.internal-as"); cValue.Exists() {
				item.Ipv4UnicastDistanceBgpInternal = types.Int64Value(cValue.Int())
			}
			if cValue := v.Get("ipv4-unicast.distance.bgp.local"); cValue.Exists() {
				item.Ipv4UnicastDistanceBgpLocal = types.Int64Value(cValue.Int())
			}
			data.Vrfs = append(data.Vrfs, item)
			return true
		})
	}
}

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

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

func (data *BGPAddressFamilyIPv4VRFData) 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 + "vrf"); value.Exists() {
		data.Vrfs = make([]BGPAddressFamilyIPv4VRFVrfs, 0)
		value.ForEach(func(k, v gjson.Result) bool {
			item := BGPAddressFamilyIPv4VRFVrfs{}
			if cValue := v.Get("name"); cValue.Exists() {
				item.Name = types.StringValue(cValue.String())
			}
			if cValue := v.Get("ipv4-unicast.advertise.l2vpn.evpn"); cValue.Exists() {
				item.Ipv4UnicastAdvertiseL2vpnEvpn = types.BoolValue(true)
			} else {
				item.Ipv4UnicastAdvertiseL2vpnEvpn = types.BoolValue(false)
			}
			if cValue := v.Get("ipv4-unicast.redistribute-vrf.connected"); cValue.Exists() {
				item.Ipv4UnicastRedistributeConnected = types.BoolValue(true)
			} else {
				item.Ipv4UnicastRedistributeConnected = types.BoolValue(false)
			}
			if cValue := v.Get("ipv4-unicast.bgp.router-id.interface.Loopback"); cValue.Exists() {
				item.Ipv4UnicastRouterIdLoopback = types.Int64Value(cValue.Int())
			}
			if cValue := v.Get("ipv4-unicast.aggregate-address"); cValue.Exists() {
				item.Ipv4UnicastAggregateAddresses = make([]BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAggregateAddresses, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAggregateAddresses{}
					if ccValue := cv.Get("ipv4-address"); ccValue.Exists() {
						cItem.Ipv4Address = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("ipv4-mask"); ccValue.Exists() {
						cItem.Ipv4Mask = types.StringValue(ccValue.String())
					}
					item.Ipv4UnicastAggregateAddresses = append(item.Ipv4UnicastAggregateAddresses, cItem)
					return true
				})
			}
			if cValue := v.Get("ipv4-unicast.redistribute-vrf.static"); cValue.Exists() {
				item.Ipv4UnicastRedistributeStatic = types.BoolValue(true)
			} else {
				item.Ipv4UnicastRedistributeStatic = types.BoolValue(false)
			}
			if cValue := v.Get("ipv4-unicast.network.with-mask"); cValue.Exists() {
				item.Ipv4UnicastNetworksMask = make([]BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworksMask, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworksMask{}
					if ccValue := cv.Get("number"); ccValue.Exists() {
						cItem.Network = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("mask"); ccValue.Exists() {
						cItem.Mask = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("route-map"); ccValue.Exists() {
						cItem.RouteMap = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("backdoor"); ccValue.Exists() {
						cItem.Backdoor = types.BoolValue(true)
					} else {
						cItem.Backdoor = types.BoolValue(false)
					}
					if ccValue := cv.Get("evpn"); ccValue.Exists() {
						cItem.Evpn = types.BoolValue(true)
					} else {
						cItem.Evpn = types.BoolValue(false)
					}
					item.Ipv4UnicastNetworksMask = append(item.Ipv4UnicastNetworksMask, cItem)
					return true
				})
			}
			if cValue := v.Get("ipv4-unicast.network.no-mask"); cValue.Exists() {
				item.Ipv4UnicastNetworks = make([]BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworks, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := BGPAddressFamilyIPv4VRFVrfsIpv4UnicastNetworks{}
					if ccValue := cv.Get("number"); ccValue.Exists() {
						cItem.Network = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("route-map"); ccValue.Exists() {
						cItem.RouteMap = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("backdoor"); ccValue.Exists() {
						cItem.Backdoor = types.BoolValue(true)
					} else {
						cItem.Backdoor = types.BoolValue(false)
					}
					if ccValue := cv.Get("evpn"); ccValue.Exists() {
						cItem.Evpn = types.BoolValue(true)
					} else {
						cItem.Evpn = types.BoolValue(false)
					}
					item.Ipv4UnicastNetworks = append(item.Ipv4UnicastNetworks, cItem)
					return true
				})
			}
			if cValue := v.Get("ipv4-unicast.distance.adm-distance"); cValue.Exists() {
				item.Ipv4UnicastAdminDistances = make([]BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAdminDistances, 0)
				cValue.ForEach(func(ck, cv gjson.Result) bool {
					cItem := BGPAddressFamilyIPv4VRFVrfsIpv4UnicastAdminDistances{}
					if ccValue := cv.Get("distance"); ccValue.Exists() {
						cItem.Distance = types.Int64Value(ccValue.Int())
					}
					if ccValue := cv.Get("srcip"); ccValue.Exists() {
						cItem.SourceIp = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("wildbits"); ccValue.Exists() {
						cItem.Wildcard = types.StringValue(ccValue.String())
					}
					if ccValue := cv.Get("acl"); ccValue.Exists() {
						cItem.Acl = types.StringValue(ccValue.String())
					}
					item.Ipv4UnicastAdminDistances = append(item.Ipv4UnicastAdminDistances, cItem)
					return true
				})
			}
			if cValue := v.Get("ipv4-unicast.distance.bgp.extern-as"); cValue.Exists() {
				item.Ipv4UnicastDistanceBgpExternal = types.Int64Value(cValue.Int())
			}
			if cValue := v.Get("ipv4-unicast.distance.bgp.internal-as"); cValue.Exists() {
				item.Ipv4UnicastDistanceBgpInternal = types.Int64Value(cValue.Int())
			}
			if cValue := v.Get("ipv4-unicast.distance.bgp.local"); cValue.Exists() {
				item.Ipv4UnicastDistanceBgpLocal = types.Int64Value(cValue.Int())
			}
			data.Vrfs = append(data.Vrfs, item)
			return true
		})
	}
}

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

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

func (data *BGPAddressFamilyIPv4VRF) getDeletedItems(ctx context.Context, state BGPAddressFamilyIPv4VRF) []string {
	deletedItems := make([]string, 0)
	for i := range state.Vrfs {
		stateKeyValues := [...]string{state.Vrfs[i].Name.ValueString()}

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

		found := false
		for j := range data.Vrfs {
			found = true
			if state.Vrfs[i].Name.ValueString() != data.Vrfs[j].Name.ValueString() {
				found = false
			}
			if found {
				if !state.Vrfs[i].Ipv4UnicastDistanceBgpLocal.IsNull() && data.Vrfs[j].Ipv4UnicastDistanceBgpLocal.IsNull() {
					deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/distance/bgp/local", state.getPath(), strings.Join(stateKeyValues[:], ",")))
				}
				if !state.Vrfs[i].Ipv4UnicastDistanceBgpInternal.IsNull() && data.Vrfs[j].Ipv4UnicastDistanceBgpInternal.IsNull() {
					deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/distance/bgp/internal-as", state.getPath(), strings.Join(stateKeyValues[:], ",")))
				}
				if !state.Vrfs[i].Ipv4UnicastDistanceBgpExternal.IsNull() && data.Vrfs[j].Ipv4UnicastDistanceBgpExternal.IsNull() {
					deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/distance/bgp/extern-as", state.getPath(), strings.Join(stateKeyValues[:], ",")))
				}
				for ci := range state.Vrfs[i].Ipv4UnicastAdminDistances {
					cstateKeyValues := [...]string{strconv.FormatInt(state.Vrfs[i].Ipv4UnicastAdminDistances[ci].Distance.ValueInt64(), 10), state.Vrfs[i].Ipv4UnicastAdminDistances[ci].SourceIp.ValueString(), state.Vrfs[i].Ipv4UnicastAdminDistances[ci].Wildcard.ValueString()}

					cemptyKeys := true
					if !reflect.ValueOf(state.Vrfs[i].Ipv4UnicastAdminDistances[ci].Distance.ValueInt64()).IsZero() {
						cemptyKeys = false
					}
					if !reflect.ValueOf(state.Vrfs[i].Ipv4UnicastAdminDistances[ci].SourceIp.ValueString()).IsZero() {
						cemptyKeys = false
					}
					if !reflect.ValueOf(state.Vrfs[i].Ipv4UnicastAdminDistances[ci].Wildcard.ValueString()).IsZero() {
						cemptyKeys = false
					}
					if cemptyKeys {
						continue
					}

					found := false
					for cj := range data.Vrfs[j].Ipv4UnicastAdminDistances {
						found = true
						if state.Vrfs[i].Ipv4UnicastAdminDistances[ci].Distance.ValueInt64() != data.Vrfs[j].Ipv4UnicastAdminDistances[cj].Distance.ValueInt64() {
							found = false
						}
						if state.Vrfs[i].Ipv4UnicastAdminDistances[ci].SourceIp.ValueString() != data.Vrfs[j].Ipv4UnicastAdminDistances[cj].SourceIp.ValueString() {
							found = false
						}
						if state.Vrfs[i].Ipv4UnicastAdminDistances[ci].Wildcard.ValueString() != data.Vrfs[j].Ipv4UnicastAdminDistances[cj].Wildcard.ValueString() {
							found = false
						}
						if found {
							if !state.Vrfs[i].Ipv4UnicastAdminDistances[ci].Acl.IsNull() && data.Vrfs[j].Ipv4UnicastAdminDistances[cj].Acl.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/distance/adm-distance=%v/acl", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							break
						}
					}
					if !found {
						deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/distance/adm-distance=%v", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
					}
				}
				for ci := range state.Vrfs[i].Ipv4UnicastNetworks {
					cstateKeyValues := [...]string{state.Vrfs[i].Ipv4UnicastNetworks[ci].Network.ValueString()}

					cemptyKeys := true
					if !reflect.ValueOf(state.Vrfs[i].Ipv4UnicastNetworks[ci].Network.ValueString()).IsZero() {
						cemptyKeys = false
					}
					if cemptyKeys {
						continue
					}

					found := false
					for cj := range data.Vrfs[j].Ipv4UnicastNetworks {
						found = true
						if state.Vrfs[i].Ipv4UnicastNetworks[ci].Network.ValueString() != data.Vrfs[j].Ipv4UnicastNetworks[cj].Network.ValueString() {
							found = false
						}
						if found {
							if !state.Vrfs[i].Ipv4UnicastNetworks[ci].Evpn.IsNull() && data.Vrfs[j].Ipv4UnicastNetworks[cj].Evpn.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/no-mask=%v/evpn", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Vrfs[i].Ipv4UnicastNetworks[ci].Backdoor.IsNull() && data.Vrfs[j].Ipv4UnicastNetworks[cj].Backdoor.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/no-mask=%v/backdoor", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Vrfs[i].Ipv4UnicastNetworks[ci].RouteMap.IsNull() && data.Vrfs[j].Ipv4UnicastNetworks[cj].RouteMap.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/no-mask=%v/route-map", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							break
						}
					}
					if !found {
						deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/no-mask=%v", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
					}
				}
				for ci := range state.Vrfs[i].Ipv4UnicastNetworksMask {
					cstateKeyValues := [...]string{state.Vrfs[i].Ipv4UnicastNetworksMask[ci].Network.ValueString(), state.Vrfs[i].Ipv4UnicastNetworksMask[ci].Mask.ValueString()}

					cemptyKeys := true
					if !reflect.ValueOf(state.Vrfs[i].Ipv4UnicastNetworksMask[ci].Network.ValueString()).IsZero() {
						cemptyKeys = false
					}
					if !reflect.ValueOf(state.Vrfs[i].Ipv4UnicastNetworksMask[ci].Mask.ValueString()).IsZero() {
						cemptyKeys = false
					}
					if cemptyKeys {
						continue
					}

					found := false
					for cj := range data.Vrfs[j].Ipv4UnicastNetworksMask {
						found = true
						if state.Vrfs[i].Ipv4UnicastNetworksMask[ci].Network.ValueString() != data.Vrfs[j].Ipv4UnicastNetworksMask[cj].Network.ValueString() {
							found = false
						}
						if state.Vrfs[i].Ipv4UnicastNetworksMask[ci].Mask.ValueString() != data.Vrfs[j].Ipv4UnicastNetworksMask[cj].Mask.ValueString() {
							found = false
						}
						if found {
							if !state.Vrfs[i].Ipv4UnicastNetworksMask[ci].Evpn.IsNull() && data.Vrfs[j].Ipv4UnicastNetworksMask[cj].Evpn.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/with-mask=%v/evpn", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Vrfs[i].Ipv4UnicastNetworksMask[ci].Backdoor.IsNull() && data.Vrfs[j].Ipv4UnicastNetworksMask[cj].Backdoor.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/with-mask=%v/backdoor", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							if !state.Vrfs[i].Ipv4UnicastNetworksMask[ci].RouteMap.IsNull() && data.Vrfs[j].Ipv4UnicastNetworksMask[cj].RouteMap.IsNull() {
								deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/with-mask=%v/route-map", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
							}
							break
						}
					}
					if !found {
						deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/with-mask=%v", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
					}
				}
				if !state.Vrfs[i].Ipv4UnicastRedistributeStatic.IsNull() && data.Vrfs[j].Ipv4UnicastRedistributeStatic.IsNull() {
					deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/redistribute-vrf/static", state.getPath(), strings.Join(stateKeyValues[:], ",")))
				}
				for ci := range state.Vrfs[i].Ipv4UnicastAggregateAddresses {
					cstateKeyValues := [...]string{state.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Address.ValueString(), state.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Mask.ValueString()}

					cemptyKeys := true
					if !reflect.ValueOf(state.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Address.ValueString()).IsZero() {
						cemptyKeys = false
					}
					if !reflect.ValueOf(state.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Mask.ValueString()).IsZero() {
						cemptyKeys = false
					}
					if cemptyKeys {
						continue
					}

					found := false
					for cj := range data.Vrfs[j].Ipv4UnicastAggregateAddresses {
						found = true
						if state.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Address.ValueString() != data.Vrfs[j].Ipv4UnicastAggregateAddresses[cj].Ipv4Address.ValueString() {
							found = false
						}
						if state.Vrfs[i].Ipv4UnicastAggregateAddresses[ci].Ipv4Mask.ValueString() != data.Vrfs[j].Ipv4UnicastAggregateAddresses[cj].Ipv4Mask.ValueString() {
							found = false
						}
						if found {
							break
						}
					}
					if !found {
						deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/aggregate-address=%v", state.getPath(), strings.Join(stateKeyValues[:], ","), strings.Join(cstateKeyValues[:], ",")))
					}
				}
				if !state.Vrfs[i].Ipv4UnicastRouterIdLoopback.IsNull() && data.Vrfs[j].Ipv4UnicastRouterIdLoopback.IsNull() {
					deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/bgp/router-id/interface/Loopback", state.getPath(), strings.Join(stateKeyValues[:], ",")))
				}
				if !state.Vrfs[i].Ipv4UnicastRedistributeConnected.IsNull() && data.Vrfs[j].Ipv4UnicastRedistributeConnected.IsNull() {
					deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/redistribute-vrf/connected", state.getPath(), strings.Join(stateKeyValues[:], ",")))
				}
				if !state.Vrfs[i].Ipv4UnicastAdvertiseL2vpnEvpn.IsNull() && data.Vrfs[j].Ipv4UnicastAdvertiseL2vpnEvpn.IsNull() {
					deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/advertise/l2vpn/evpn", state.getPath(), strings.Join(stateKeyValues[:], ",")))
				}
				break
			}
		}
		if !found {
			deletedItems = append(deletedItems, fmt.Sprintf("%v/vrf=%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 *BGPAddressFamilyIPv4VRF) getEmptyLeafsDelete(ctx context.Context) []string {
	emptyLeafsDelete := make([]string, 0)

	for i := range data.Vrfs {
		keyValues := [...]string{data.Vrfs[i].Name.ValueString()}

		for ci := range data.Vrfs[i].Ipv4UnicastNetworks {
			ckeyValues := [...]string{data.Vrfs[i].Ipv4UnicastNetworks[ci].Network.ValueString()}
			if !data.Vrfs[i].Ipv4UnicastNetworks[ci].Evpn.IsNull() && !data.Vrfs[i].Ipv4UnicastNetworks[ci].Evpn.ValueBool() {
				emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/no-mask=%v/evpn", data.getPath(), strings.Join(keyValues[:], ","), strings.Join(ckeyValues[:], ",")))
			}
			if !data.Vrfs[i].Ipv4UnicastNetworks[ci].Backdoor.IsNull() && !data.Vrfs[i].Ipv4UnicastNetworks[ci].Backdoor.ValueBool() {
				emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/no-mask=%v/backdoor", data.getPath(), strings.Join(keyValues[:], ","), strings.Join(ckeyValues[:], ",")))
			}
		}

		for ci := range data.Vrfs[i].Ipv4UnicastNetworksMask {
			ckeyValues := [...]string{data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Network.ValueString(), data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Mask.ValueString()}
			if !data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Evpn.IsNull() && !data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Evpn.ValueBool() {
				emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/with-mask=%v/evpn", data.getPath(), strings.Join(keyValues[:], ","), strings.Join(ckeyValues[:], ",")))
			}
			if !data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Backdoor.IsNull() && !data.Vrfs[i].Ipv4UnicastNetworksMask[ci].Backdoor.ValueBool() {
				emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/network/with-mask=%v/backdoor", data.getPath(), strings.Join(keyValues[:], ","), strings.Join(ckeyValues[:], ",")))
			}
		}
		if !data.Vrfs[i].Ipv4UnicastRedistributeStatic.IsNull() && !data.Vrfs[i].Ipv4UnicastRedistributeStatic.ValueBool() {
			emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/redistribute-vrf/static", data.getPath(), strings.Join(keyValues[:], ",")))
		}

		if !data.Vrfs[i].Ipv4UnicastRedistributeConnected.IsNull() && !data.Vrfs[i].Ipv4UnicastRedistributeConnected.ValueBool() {
			emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/redistribute-vrf/connected", data.getPath(), strings.Join(keyValues[:], ",")))
		}
		if !data.Vrfs[i].Ipv4UnicastAdvertiseL2vpnEvpn.IsNull() && !data.Vrfs[i].Ipv4UnicastAdvertiseL2vpnEvpn.ValueBool() {
			emptyLeafsDelete = append(emptyLeafsDelete, fmt.Sprintf("%v/vrf=%v/ipv4-unicast/advertise/l2vpn/evpn", data.getPath(), strings.Join(keyValues[:], ",")))
		}
	}

	return emptyLeafsDelete
}

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

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

func (data *BGPAddressFamilyIPv4VRF) getDeletePaths(ctx context.Context) []string {
	var deletePaths []string
	for i := range data.Vrfs {
		keyValues := [...]string{data.Vrfs[i].Name.ValueString()}

		deletePaths = append(deletePaths, fmt.Sprintf("%v/vrf=%v", data.getPath(), strings.Join(keyValues[:], ",")))
	}

	return deletePaths
}

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