/*
Copyright (c) 2019-2022 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>
Tim Tkachev, <tvtkachev@basistech.ru>

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 flipgroup

import (
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)

func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.RecordFLIPGroup) {
	d.Set("account_id", fg.AccountID)
	d.Set("account_name", fg.AccountName)
	d.Set("client_ids", fg.ClientIDs)
	d.Set("client_type", fg.ClientType)
	d.Set("conn_id", fg.ConnID)
	d.Set("conn_type", fg.ConnType)
	d.Set("created_by", fg.CreatedBy)
	d.Set("created_time", fg.CreatedTime)
	d.Set("default_gw", fg.DefaultGW)
	d.Set("deleted_by", fg.DeletedBy)
	d.Set("deleted_time", fg.DeletedTime)
	d.Set("desc", fg.Description)
	d.Set("gid", fg.GID)
	d.Set("guid", fg.GUID)
	d.Set("flipgroup_id", fg.ID)
	d.Set("ip", fg.IP)
	d.Set("milestones", fg.Milestones)
	d.Set("name", fg.Name)
	d.Set("net_id", fg.NetID)
	d.Set("net_type", fg.NetType)
	d.Set("network", fg.Network)
	d.Set("status", fg.Status)
	d.Set("updated_by", fg.UpdatedBy)
	d.Set("updated_time", fg.UpdatedTime)
}

func flattenFlipgroupList(fg_list *flipgroup.ListFLIPGroups) []map[string]interface{} {
	res := make([]map[string]interface{}, 0)
	for _, fg := range fg_list.Data {
		temp := map[string]interface{}{
			"ckey":         fg.CKey,
			"meta":         flattens.FlattenMeta(fg.Meta),
			"account_id":   fg.AccountID,
			"client_ids":   fg.ClientIDs,
			"client_type":  fg.ClientType,
			"conn_id":      fg.ConnID,
			"conn_type":    fg.ConnType,
			"default_gw":   fg.DefaultGW,
			"desc":         fg.Description,
			"gid":          fg.GID,
			"guid":         fg.GUID,
			"flipgroup_id": fg.ID,
			"ip":           fg.IP,
			"milestones":   fg.Milestones,
			"name":         fg.Name,
			"net_id":       fg.NetID,
			"net_type":     fg.NetType,
			"net_mask":     fg.NetMask,
			"status":       fg.Status,
		}
		res = append(res, temp)
	}

	return res
}
