/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
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 k8ci

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

func flattenK8CIListItems(list *k8ci.ListK8CI) []map[string]interface{} {
	log.Debug("flattenK8CIListItems")
	res := make([]map[string]interface{}, 0, len(list.Data))
	for _, item := range list.Data {
		temp := map[string]interface{}{
			"created_time":     item.CreatedTime,
			"desc":             item.Description,
			"gid":              item.GID,
			"guid":             item.GUID,
			"k8ci_id":          item.ID,
			"lb_image_id":      item.LBImageID,
			"master_image_id":  item.MasterImageID,
			"max_master_count": item.MaxMasterCount,
			"max_worker_count": item.MaxWorkerCount,
			"name":             item.Name,
			"shared_with":      item.SharedWith,
			"status":           item.Status,
			"version":          item.Version,
			"worker_image_id":  item.WorkerImageID,
		}
		res = append(res, temp)
	}

	return res
}

func flattenK8CIItems(d *schema.ResourceData, data *k8ci.RecordK8CI) error {
	log.Debugf("flattenK8CI: ID %d", data.ID)

	d.Set("desc", data.Description)
	d.Set("gid", data.GID)
	d.Set("guid", data.GUID)
	d.Set("k8ci_id", data.ID)
	d.Set("lb_image_id", data.LBImageID)
	d.Set("master_image_id", data.MasterImageID)
	d.Set("max_master_count", data.MaxMasterCount)
	d.Set("max_worker_count", data.MaxWorkerCount)
	d.Set("milestones", data.Milestones)
	d.Set("name", data.Name)
	d.Set("network_plugins", data.NetworkPlugins)
	d.Set("shared_with", data.SharedWith)
	d.Set("status", data.Status)
	d.Set("version", data.Version)
	d.Set("worker_image_id", data.WorkerImageID)

	return nil
}
