/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@digitalenergy.online>

Licensed under the Apache 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

    http://www.apache.org/licenses/LICENSE-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.
*/

/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.

Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort

Please see README.md to learn where to place source code so that it
builds seamlessly.

Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/

package vins

import (
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	log "github.com/sirupsen/logrus"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)

func flattenVins(d *schema.ResourceData, vinsRecord *vins.RecordVINS) {
	d.Set("vnf_dev", flattenVinsVNFDev(vinsRecord.VNFDev))
	d.Set("account_id", vinsRecord.AccountID)
	d.Set("account_name", vinsRecord.AccountName)
	d.Set("created_by", vinsRecord.CreatedBy)
	d.Set("created_time", vinsRecord.CreatedTime)
	d.Set("default_gw", vinsRecord.DefaultGW)
	d.Set("default_qos", flattenVinsQOS(vinsRecord.DefaultQOS))
	d.Set("deleted_by", vinsRecord.DeletedBy)
	d.Set("deleted_time", vinsRecord.DeletedTime)
	d.Set("description", vinsRecord.Description)
	d.Set("gid", vinsRecord.GID)
	d.Set("guid", vinsRecord.GUID)
	d.Set("vins_id", vinsRecord.ID)
	d.Set("lock_status", vinsRecord.LockStatus)
	d.Set("manager_id", vinsRecord.ManagerID)
	d.Set("manager_type", vinsRecord.ManagerType)
	d.Set("milestones", vinsRecord.Milestones)
	d.Set("name", vinsRecord.Name)
	d.Set("netmask", vinsRecord.NetMask)
	d.Set("network", vinsRecord.Network)
	d.Set("pre_reservations_num", vinsRecord.PreReservationsNum)
	d.Set("redundant", vinsRecord.Redundant)
	d.Set("rg_id", vinsRecord.RGID)
	d.Set("rg_name", vinsRecord.RGName)
	d.Set("sec_vnf_dev_id", vinsRecord.SecVNFDevID)
	d.Set("status", vinsRecord.Status)
	d.Set("updated_by", vinsRecord.UpdatedBy)
	d.Set("updated_time", vinsRecord.UpdatedTime)
	d.Set("user_managed", vinsRecord.UserManaged)
	d.Set("vnfs", flattenVinsRecordVNFs(vinsRecord.VNFs))
	d.Set("vxlan_id", vinsRecord.VXLANID)
	d.Set("nat_rule", flattenRuleBlock(vinsRecord.VNFs.NAT.Config.Rules))
	d.Set("computes", flattenComputes(vinsRecord.Computes))
	d.Set("zone_id", vinsRecord.ZoneID)
}

func flattenVinsData(d *schema.ResourceData, vinsRecord *vins.RecordVINS) {
	log.Debugf("flattenVins: decoded ViNS name: %s, ID : %d, account ID %d, RG ID %d",
		vinsRecord.Name, vinsRecord.ID, vinsRecord.AccountID, vinsRecord.RGID)

	d.Set("vnf_dev", flattenVinsVNFDev(vinsRecord.VNFDev))
	d.Set("account_id", vinsRecord.AccountID)
	d.Set("account_name", vinsRecord.AccountName)
	d.Set("created_by", vinsRecord.CreatedBy)
	d.Set("created_time", vinsRecord.CreatedTime)
	d.Set("default_gw", vinsRecord.DefaultGW)
	d.Set("default_qos", flattenVinsQOS(vinsRecord.DefaultQOS))
	d.Set("deleted_by", vinsRecord.DeletedBy)
	d.Set("deleted_time", vinsRecord.DeletedTime)
	d.Set("description", vinsRecord.Description)
	d.Set("gid", vinsRecord.GID)
	d.Set("guid", vinsRecord.GUID)
	d.Set("vins_id", vinsRecord.ID)
	d.Set("lock_status", vinsRecord.LockStatus)
	d.Set("manager_id", vinsRecord.ManagerID)
	d.Set("manager_type", vinsRecord.ManagerType)
	d.Set("milestones", vinsRecord.Milestones)
	d.Set("name", vinsRecord.Name)
	d.Set("netmask", vinsRecord.NetMask)
	d.Set("network", vinsRecord.Network)
	d.Set("pre_reservations_num", vinsRecord.PreReservationsNum)
	d.Set("redundant", vinsRecord.Redundant)
	d.Set("rg_id", vinsRecord.RGID)
	d.Set("rg_name", vinsRecord.RGName)
	d.Set("sec_vnf_dev_id", vinsRecord.SecVNFDevID)
	d.Set("status", vinsRecord.Status)
	d.Set("updated_by", vinsRecord.UpdatedBy)
	d.Set("updated_time", vinsRecord.UpdatedTime)
	d.Set("user_managed", vinsRecord.UserManaged)
	d.Set("vnfs", flattenVinsRecordVNFs(vinsRecord.VNFs))
	d.Set("vxlan_id", vinsRecord.VXLANID)
	d.Set("computes", flattenComputes(vinsRecord.Computes))
	d.Set("zone_id", vinsRecord.ZoneID)
	d.Set("enable_secgroups", vinsRecord.EnableSecGroups)

}

func flattenLibvirtSettings(libvirtSettings vins.LibvirtSettings) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"guid":          libvirtSettings.GUID,
		"txmode":        libvirtSettings.TXMode,
		"ioeventfd":     libvirtSettings.IOEventFD,
		"event_idx":     libvirtSettings.EventIDx,
		"queues":        libvirtSettings.Queues,
		"rx_queue_size": libvirtSettings.RXQueueSize,
		"tx_queue_size": libvirtSettings.TXQueueSize,
	}
	res = append(res, temp)
	return res
}

func flattenVinsVNFDev(vd vins.VNFDev) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"ckey":                  vd.CKey,
		"meta":                  flattens.FlattenMeta(vd.Meta),
		"account_id":            vd.AccountID,
		"capabilities":          vd.Capabilities,
		"config":                flattenVinsConfig(vd.Config),
		"config_saved":          vd.ConfigSaved,
		"custom_precfg":         vd.CustomPreConfig,
		"description":           vd.Description,
		"gid":                   vd.GID,
		"guid":                  vd.GUID,
		"id":                    vd.ID,
		"interfaces":            flattenVinsListInterfaces(vd.Interfaces),
		"live_migration_job_id": vd.LiveMigrationJobID,
		"lock_status":           vd.LockStatus,
		"milestones":            vd.Milestones,
		"name":                  vd.Name,
		"status":                vd.Status,
		"tech_status":           vd.TechStatus,
		"type":                  vd.Type,
		"vnc_password":          vd.VNCPassword,
		"vins":                  vd.VINS,
		"zone_id":               vd.ZoneID,
	}
	res = append(res, temp)
	return res
}

func flattenComputes(computes []vins.Computes) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(computes))
	for _, compute := range computes {
		tmp := map[string]interface{}{
			"id":   compute.ID,
			"name": compute.Name,
		}
		res = append(res, tmp)
	}
	return res
}

func flattenVinsRecordVNFs(rv vins.RecordVNFs) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"dhcp": flattenVinsRecordDHCP(rv.DHCP),
		"gw":   flattenVinsRecordGW(rv.GW),
		"nat":  flattenVinsRecordNAT(rv.NAT),
	}
	res = append(res, temp)
	return res
}

func flattenVinsRecordDHCP(rv vins.RecordDHCP) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"config":       flattenVinsVNFsConfig(rv.Config),
		"ckey":         rv.CKey,
		"meta":         flattens.FlattenMeta(rv.Meta),
		"account_id":   rv.AccountID,
		"created_time": rv.CreatedTime,
		"devices":      flattenVinsPrimaryDevices(rv.Devices),
		"gid":          rv.GID,
		"guid":         rv.GUID,
		"id":           rv.ID,
		"lock_status":  rv.LockStatus,
		"milestones":   rv.Milestones,
		"owner_id":     rv.OwnerID,
		"owner_type":   rv.OwnerType,
		"pure_virtual": rv.PureVirtual,
		"routes":       flattenVinsRoutes(rv.Routes),
		"status":       rv.Status,
		"tech_status":  rv.TechStatus,
		"type":         rv.Type,
		"zone_id":      rv.ZoneID,
	}
	res = append(res, temp)
	return res
}

func flattenVinsRecordGW(rg vins.RecordGW) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"config":       flattenVinsGWConfig(rg.Config),
		"ckey":         rg.CKey,
		"meta":         flattens.FlattenMeta(rg.Meta),
		"account_id":   rg.AccountID,
		"created_time": rg.CreatedTime,
		"devices":      flattenVinsPrimaryDevices(rg.Devices),
		"gid":          rg.GID,
		"guid":         rg.GUID,
		"id":           rg.ID,
		"lock_status":  rg.LockStatus,
		"milestones":   rg.Milestones,
		"owner_id":     rg.OwnerID,
		"owner_type":   rg.OwnerType,
		"pure_virtual": rg.PureVirtual,
		"routes":       flattenVinsRoutes(rg.Routes),
		"status":       rg.Status,
		"tech_status":  rg.TechStatus,
		"type":         rg.Type,
		"zone_id":      rg.ZoneID,
	}
	res = append(res, temp)
	return res
}

func flattenVinsRecordNAT(rn vins.RecordNAT) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"config":       flattenVinsNATConfig(rn.Config),
		"ckey":         rn.CKey,
		"meta":         flattens.FlattenMeta(rn.Meta),
		"account_id":   rn.AccountID,
		"created_time": rn.CreatedTime,
		"devices":      flattenVinsPrimaryDevices(rn.Devices),
		"gid":          rn.GID,
		"guid":         rn.GUID,
		"id":           rn.ID,
		"lock_status":  rn.LockStatus,
		"milestones":   rn.Milestones,
		"owner_id":     rn.OwnerID,
		"owner_type":   rn.OwnerType,
		"pure_virtual": rn.PureVirtual,
		"routes":       flattenVinsRoutes(rn.Routes),
		"status":       rn.Status,
		"tech_status":  rn.TechStatus,
		"type":         rn.Type,
		"zone_id":      rn.ZoneID,
	}
	res = append(res, temp)
	return res
}

func flattenVinsVNFsConfig(vc vins.VNFsConfig) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"default_gw":   vc.DefaultGW,
		"dns":          vc.DNS,
		"ip_end":       vc.IPEnd,
		"ip_start":     vc.IPStart,
		"lease":        vc.Lease,
		"net_mask":     vc.NetMask,
		"network":      vc.Network,
		"reservations": flattenVinsListReservations(vc.Reservations),
	}
	res = append(res, temp)
	return res
}

func flattenVinsGWConfig(gc vins.GWConfig) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"default_gw":  gc.DefaultGW,
		"ext_net_id":  gc.ExtNetID,
		"ext_net_ip":  gc.ExtNetIP,
		"ext_netmask": gc.ExtNetMask,
		"qos":         flattenVinsQOS(gc.QOS),
	}
	res = append(res, temp)
	return res
}

func flattenVinsNATConfig(nc vins.NATConfig) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"net_mask": nc.NetMask,
		"network":  nc.Network,
		"rules":    flattenRulesItem(nc.Rules),
	}
	res = append(res, temp)
	return res
}

func flattenRuleBlock(rules []vins.ItemNATRule) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(rules))
	for _, rule := range rules {
		tmp := map[string]interface{}{
			"int_ip":         rule.LocalIP,
			"int_port":       rule.LocalPort,
			"ext_port_start": rule.PublicPortStart,
			"ext_port_end":   rule.PublicPortEnd,
			"proto":          rule.Protocol,
			"rule_id":        rule.ID,
		}
		res = append(res, tmp)
	}
	return res
}

func flattenRulesItem(rules []vins.ItemNATRule) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(rules))
	for _, rule := range rules {
		tmp := map[string]interface{}{
			"rule_id":           rule.ID,
			"local_ip":          rule.LocalIP,
			"local_port":        rule.LocalPort,
			"protocol":          rule.Protocol,
			"public_port_end":   rule.PublicPortEnd,
			"public_port_start": rule.PublicPortStart,
			"vm_id":             rule.VMID,
			"vm_name":           rule.VMName,
		}
		res = append(res, tmp)
	}
	return res
}

func flattenVinsPrimaryDevices(d vins.Devices) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"primary": flattenVinsDevices(d.Primary),
	}
	res = append(res, temp)
	return res
}

func flattenVinsDevices(d vins.Primary) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"dev_id":  d.DevID,
		"iface01": d.IFace01,
		"iface02": d.IFace02,
	}
	res = append(res, temp)
	return res
}

func flattenVinsRoutes(r vins.ListRoutes) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(r))
	for _, v := range r {
		temp := map[string]interface{}{
			"destination": v.Destination,
			"netmask":     v.Netmask,
			"gateway":     v.Gateway,
			"compute_ids": v.ComputeIds,
			"guid":        v.GUID,
			"route_id":    v.ID,
		}
		res = append(res, temp)
	}
	return res
}

func flattenVinsListReservations(li vins.ListReservations) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(li))
	for _, v := range li {
		temp := map[string]interface{}{
			"account_id": v.AccountID,
			"ip":         v.IP,
			"mac":        v.MAC,
			"type":       v.Type,
			"vm_id":      v.VMID,
		}
		res = append(res, temp)
	}
	return res
}

func flattenVinsConfig(c vins.Config) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"mgmt":      flattenVinsMGMT(c.MGMT),
		"resources": flattenVinsResources(c.Resources),
	}
	res = append(res, temp)
	return res
}

func flattenVinsMGMT(m vins.MGMT) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"ip_addr":  m.IPAddress,
		"password": m.Password,
		"ssh_key":  m.SSHKey,
		"user":     m.User,
	}
	res = append(res, temp)
	return res
}

func flattenVinsResources(r vins.Resources) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"cpu":     r.CPU,
		"ram":     r.RAM,
		"node_id": r.NodeID,
		"uuid":    r.UUID,
	}
	res = append(res, temp)
	return res
}

func flattenVinsListInterfaces(i vins.ListInterfaces) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(i))
	for _, v := range i {
		temp := map[string]interface{}{
			"conn_id":          v.ConnID,
			"conn_type":        v.ConnType,
			"def_gw":           v.DefGW,
			"enabled":          v.Enabled,
			"enable_secgroups": v.EnableSecGroups,
			"flipgroup_id":     v.FLIPGroupID,
			"guid":             v.GUID,
			"ip_address":       v.IPAddress,
			"listen_ssh":       v.ListenSSH,
			"mac":              v.MAC,
			"mtu":              v.MTU,
			"name":             v.Name,
			"net_id":           v.NetID,
			"net_mask":         v.NetMask,
			"net_type":         v.NetType,
			"node_id":          v.NodeID,
			"pci_slot":         v.PCISlot,
			"bus_number":       v.BusNumber,
			"qos":              flattenVinsQOS(v.QOS),
			"security_groups":  v.SecGroups,
			"sdn_interface_id": v.SDNInterfaceID,
			"target":           v.Target,
			"type":             v.Type,
			"vnfs":             v.VNFs,
			"libvirt_settings": flattenLibvirtSettings(v.LibvirtSettings),
		}
		res = append(res, temp)
	}
	return res
}

func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(vl.Data))
	for _, v := range vl.Data {
		temp := map[string]interface{}{
			"account_id":           v.AccountID,
			"account_name":         v.AccountName,
			"created_by":           v.CreatedBy,
			"created_time":         v.CreatedTime,
			"default_gw":           v.DefaultGW,
			"default_qos":          flattenVinsQOS(v.DefaultQOS),
			"deleted_by":           v.DeletedBy,
			"deleted_time":         v.DeletedTime,
			"description":          v.Description,
			"enable_secgroups":     v.EnableSecGroups,
			"external_ip":          v.ExternalIP,
			"extnet_id":            v.ExtnetId,
			"free_ips":             v.FreeIPs,
			"gid":                  v.GID,
			"guid":                 v.GUID,
			"vins_id":              v.ID,
			"name":                 v.Name,
			"lock_status":          v.LockStatus,
			"manager_id":           v.ManagerID,
			"manager_type":         v.ManagerType,
			"milestones":           v.Milestones,
			"netmask":              v.NetMask,
			"network":              v.Network,
			"pre_reservations_num": v.PreReservationsNum,
			"pri_vnf_dev_id":       v.PriVNFDevID,
			"redundant":            v.Redundant,
			"rg_id":                v.RGID,
			"rg_name":              v.RGName,
			"sec_vnf_dev_id":       v.SecVNFDevID,
			"status":               v.Status,
			"updated_by":           v.UpdatedBy,
			"updated_time":         v.UpdatedTime,
			"user_managed":         v.UserManaged,
			"vnfs":                 flattenVinsVNFs(v.VNFs),
			"vxlan_id":             v.VXLANID,
			"zone_id":              v.ZoneID,
		}
		res = append(res, temp)
	}
	return res
}

func flattenVinsListDeleted(vl *vins.ListVINS) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(vl.Data))
	for _, v := range vl.Data {
		temp := map[string]interface{}{
			"account_id":           v.AccountID,
			"account_name":         v.AccountName,
			"created_by":           v.CreatedBy,
			"created_time":         v.CreatedTime,
			"default_gw":           v.DefaultGW,
			"default_qos":          flattenVinsQOS(v.DefaultQOS),
			"deleted_by":           v.DeletedBy,
			"deleted_time":         v.DeletedTime,
			"description":          v.Description,
			"external_ip":          v.ExternalIP,
			"gid":                  v.GID,
			"guid":                 v.GUID,
			"vins_id":              v.ID,
			"name":                 v.Name,
			"lock_status":          v.LockStatus,
			"manager_id":           v.ManagerID,
			"manager_type":         v.ManagerType,
			"milestones":           v.Milestones,
			"netmask":              v.NetMask,
			"network":              v.Network,
			"pre_reservations_num": v.PreReservationsNum,
			"pri_vnf_dev_id":       v.PriVNFDevID,
			"redundant":            v.Redundant,
			"rg_id":                v.RGID,
			"rg_name":              v.RGName,
			"sec_vnf_dev_id":       v.SecVNFDevID,
			"status":               v.Status,
			"updated_by":           v.UpdatedBy,
			"updated_time":         v.UpdatedTime,
			"user_managed":         v.UserManaged,
			"vnfs":                 flattenVinsVNFs(v.VNFs),
			"vxlan_id":             v.VXLANID,
			"zone_id":              v.ZoneID,
		}
		res = append(res, temp)
	}
	return res
}

func flattenVinsVNFs(iv vins.ItemVNFs) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"dhcp": iv.DHCP,
		"dns":  iv.DNS,
		"fw":   iv.FW,
		"gw":   iv.GW,
		"nat":  iv.NAT,
		"vpn":  iv.VPN,
	}
	res = append(res, temp)
	return res
}

func flattenVinsQOS(dq vins.QOS) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	temp := map[string]interface{}{
		"e_rate":   dq.ERate,
		"guid":     dq.GUID,
		"in_burst": dq.InBurst,
		"in_rate":  dq.InRate,
	}
	res = append(res, temp)
	return res
}

func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(auidts))
	for _, audit := range auidts {
		temp := map[string]interface{}{
			"call":          audit.Call,
			"response_time": audit.ResponseTime,
			"status_code":   audit.StatusCode,
			"time_stamp":    audit.Timestamp,
			"user":          audit.User,
		}
		res = append(res, temp)
	}

	return res
}

func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(extNetList.Data))
	for _, extNet := range extNetList.Data {
		temp := map[string]interface{}{
			"default_gw":  extNet.DefaultGW,
			"ext_net_id":  extNet.ExtNetID,
			"ip":          extNet.IP,
			"prefix_len":  extNet.PrefixLen,
			"status":      extNet.Status,
			"tech_status": extNet.TechStatus,
		}
		res = append(res, temp)
	}

	return res
}

func flattenVinsNatRuleList(natRules *vins.ListNATRules) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(natRules.Data))
	for _, natRule := range natRules.Data {
		temp := map[string]interface{}{
			"id":                natRule.ID,
			"local_ip":          natRule.LocalIP,
			"local_port":        natRule.LocalPort,
			"protocol":          natRule.Protocol,
			"public_port_end":   natRule.PublicPortEnd,
			"public_port_start": natRule.PublicPortStart,
			"vm_id":             natRule.VMID,
			"vm_name":           natRule.VMName,
		}
		res = append(res, temp)
	}

	return res
}

func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(ips.Data))
	for _, ip := range ips.Data {
		temp := map[string]interface{}{
			"client_type": ip.ClientType,
			"domain_name": ip.DomainName,
			"host_name":   ip.Hostname,
			"ip":          ip.IP,
			"mac":         ip.MAC,
			"type":        ip.Type,
			"vm_id":       ip.VMID,
		}
		res = append(res, temp)
	}

	return res
}

func flattenStaticRouteList(sr *vins.ListStaticRoutes) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(sr.Data))
	for _, staticRoute := range sr.Data {
		temp := map[string]interface{}{
			"route_id":    staticRoute.ID,
			"destination": staticRoute.Destination,
			"gateway":     staticRoute.Gateway,
			"guid":        staticRoute.GUID,
			"netmask":     staticRoute.Netmask,
			"compute_ids": staticRoute.ComputeIds,
		}
		res = append(res, temp)
	}

	return res
}

func flattenStaticRouteData(d *schema.ResourceData, route *vins.ItemRoutes) {
	d.Set("destination", route.Destination)
	d.Set("gateway", route.Gateway)
	d.Set("guid", route.GUID)
	d.Set("netmask", route.Netmask)
	d.Set("compute_ids", route.ComputeIds)
	d.Set("route_id", route.ID)
}
