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

import (
	"context"

	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image"
)

func CreateRequest(ctx context.Context, d *schema.ResourceData, m interface{}, url string) (image.CreateRequest, error) {
	req := image.CreateRequest{
		Name:            d.Get("name").(string),
		URL:             url,
		BootType:        d.Get("boot_type").(string),
		ImageType:       d.Get("image_type").(string),
		StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
	}

	if hotresize, ok := d.GetOk("hot_resize"); ok {
		req.HotResize = hotresize.(bool)
	}
	if username, ok := d.GetOk("username"); ok {
		req.Username = username.(string)
	}
	if password, ok := d.GetOk("password"); ok {
		req.Password = password.(string)
	}
	if accountId, ok := d.GetOk("account_id"); ok {
		req.AccountID = uint64(accountId.(int))
	}
	if usernameDL, ok := d.GetOk("username_dl"); ok {
		req.UsernameDL = usernameDL.(string)
	}
	if passwordDL, ok := d.GetOk("password_dl"); ok {
		req.PasswordDL = passwordDL.(string)
	}
	if sepId, ok := d.GetOk("sep_id"); ok {
		req.SEPID = uint64(sepId.(int))
	}
	if poolName, ok := d.GetOk("pool_name"); ok {
		req.PoolName = poolName.(string)
	}
	if bootable, ok := d.GetOk("bootable"); ok {
		req.Bootable = bootable.(bool)
	}
	if networkInterfaceNaming, ok := d.GetOk("network_interface_naming"); ok {
		req.NetworkInterfaceNaming = networkInterfaceNaming.(string)
	}
	return req, nil
}
