package trunk

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

func flattenTrunk(d *schema.ResourceData, trunkItem *trunk.ItemTrunk) {
	log.Debugf("flattenTrunk: decoded Trunk ID %d",
		trunkItem.ID)

	d.Set("trunk_id", trunkItem.ID)
	d.Set("guid", trunkItem.GUID)
	d.Set("name", trunkItem.Name)
	d.Set("mac", trunkItem.MAC)
	d.Set("description", trunkItem.Description)
	d.Set("account_ids", trunkItem.AccountIDs)
	d.Set("ovs_bridge", trunkItem.OVSBridge)
	d.Set("native_vlan_id", trunkItem.NativeVLANID)
	d.Set("mtu", trunkItem.MTU)
	d.Set("status", trunkItem.Status)
	d.Set("trunk_tags", trunkItem.TrunkTags)
	d.Set("created_at", trunkItem.CreatedAt)
	d.Set("created_by", trunkItem.CreatedBy)
	d.Set("updated_at", trunkItem.UpdatedAt)
	d.Set("updated_by", trunkItem.UpdatedBy)
	d.Set("deleted_at", trunkItem.DeletedAt)
	d.Set("deleted_by", trunkItem.DeletedBy)
}

func flattenTrunkList(trunkList *trunk.ListTrunks) []map[string]interface{} {
	res := make([]map[string]interface{}, 0, len(trunkList.Data))
	for _, trunkItem := range trunkList.Data {
		temp := map[string]interface{}{
			"account_ids":    trunkItem.AccountIDs,
			"created_at":     trunkItem.CreatedAt,
			"created_by":     trunkItem.CreatedBy,
			"deleted_at":     trunkItem.DeletedAt,
			"deleted_by":     trunkItem.DeletedBy,
			"description":    trunkItem.Description,
			"guid":           trunkItem.GUID,
			"id":             trunkItem.ID,
			"mac":            trunkItem.MAC,
			"name":           trunkItem.Name,
			"native_vlan_id": trunkItem.NativeVLANID,
			"ovs_bridge":     trunkItem.OVSBridge,
			"mtu":            trunkItem.MTU,
			"status":         trunkItem.Status,
			"trunk_tags":     trunkItem.TrunkTags,
			"updated_at":     trunkItem.UpdatedAt,
			"updated_by":     trunkItem.UpdatedBy,
		}
		res = append(res, temp)
	}

	return res
}
