package pcidevice

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

func flattenPcidevice(d *schema.ResourceData, pd *pcidevice.ItemPCIDevice) {
	log.Debugf("flattenPCIDevice: ID %d", pd.ID)

	d.Set("compute_id", pd.ComputeID)
	d.Set("description", pd.Description)
	d.Set("guid", pd.GUID)
	d.Set("hw_path", pd.HwPath)
	d.Set("device_id", pd.ID)
	d.Set("name", pd.Name)
	d.Set("rg_id", pd.RGID)
	d.Set("node_id", pd.NodeID)
	d.Set("status", pd.Status)
	d.Set("system_name", pd.SystemName)
}

func flattenPcideviceList(pl *pcidevice.ListPCIDevices) []map[string]interface{} {
	log.Debug("flattenPCIDeviceList")

	res := make([]map[string]interface{}, 0, len(pl.Data))
	for _, item := range pl.Data {
		temp := map[string]interface{}{
			"compute_id":  item.ComputeID,
			"description": item.Description,
			"guid":        item.GUID,
			"hw_path":     item.HwPath,
			"device_id":   item.ID,
			"rg_id":       item.RGID,
			"name":        item.Name,
			"node_id":     item.NodeID,
			"status":      item.Status,
			"system_name": item.SystemName,
		}
		res = append(res, temp)
	}
	return res
}
