package disks

import (
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceDiskV1() *schema.Resource {
	return &schema.Resource{
		Schema: map[string]*schema.Schema{
			"account_id": {
				Type:     schema.TypeInt,
				Required: true,
				//ForceNew:    true,
				Description: "The unique ID of the subscriber-owner of the disk",
			},
			"disk_name": {
				Type:        schema.TypeString,
				Required:    true,
				Description: "Name of disk",
			},
			"size_max": {
				Type:        schema.TypeInt,
				Required:    true,
				Description: "Size in GB",
			},
			"gid": {
				Type:     schema.TypeInt,
				Required: true,
				//ForceNew:    true,
				Description: "ID of the grid (platform)",
			},
			"pool": {
				Type:        schema.TypeString,
				Optional:    true,
				Computed:    true,
				Description: "Pool for disk location",
			},
			"sep_id": {
				Type:        schema.TypeInt,
				Optional:    true,
				Computed:    true,
				Description: "Storage endpoint provider ID to create disk",
			},
			"desc": {
				Type:        schema.TypeString,
				Optional:    true,
				Computed:    true,
				Description: "Description of disk",
			},
			"type": {
				Type:         schema.TypeString,
				Optional:     true,
				Computed:     true,
				ValidateFunc: validation.StringInSlice([]string{"D", "B", "T"}, false),
				Description:  "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
			},
			"detach": {
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     false,
				Description: "Detaching the disk from compute",
			},
			"permanently": {
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     false,
				Description: "Whether to completely delete the disk, works only with non attached disks",
			},
			"shareable": {
				Type:     schema.TypeBool,
				Optional: true,
				Computed: true,
			},
			"iotune": {
				Type:     schema.TypeList,
				Optional: true,
				MaxItems: 1,
				Computed: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"read_bytes_sec": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Number of bytes to read per second",
						},
						"read_bytes_sec_max": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Maximum number of bytes to read",
						},
						"read_iops_sec": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Number of io read operations per second",
						},
						"read_iops_sec_max": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Maximum number of io read operations",
						},
						"size_iops_sec": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Size of io operations",
						},
						"total_bytes_sec": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Total size bytes per second",
						},
						"total_bytes_sec_max": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Maximum total size of bytes per second",
						},
						"total_iops_sec": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Total number of io operations per second",
						},
						"total_iops_sec_max": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Maximum total number of io operations per second",
						},
						"write_bytes_sec": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Number of bytes to write per second",
						},
						"write_bytes_sec_max": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Maximum number of bytes to write per second",
						},
						"write_iops_sec": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Number of write operations per second",
						},
						"write_iops_sec_max": {
							Type:        schema.TypeInt,
							Optional:    true,
							Computed:    true,
							Description: "Maximum number of write operations per second",
						},
					},
				},
			},
			"present_to": {
				Type:     schema.TypeList,
				Computed: true,
				Elem: &schema.Schema{
					Type: schema.TypeInt,
				},
			},
			"disk_id": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Disk ID. Duplicates the value of the ID parameter",
			},
			"account_name": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "The name of the subscriber '(account') to whom this disk belongs",
			},
			"acl": {
				Type:     schema.TypeString,
				Computed: true,
			},
			// "boot_partition": {
			// 	Type:        schema.TypeInt,
			// 	Computed:    true,
			// 	Description: "Number of disk partitions",
			// },
			"computes": {
				Type:     schema.TypeList,
				Computed: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"compute_id": {
							Type:     schema.TypeString,
							Computed: true,
						},
						"compute_name": {
							Type:     schema.TypeString,
							Computed: true,
						},
					},
				},
			},
			"created_time": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Created time",
			},
			"deleted_time": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Deleted time",
			},
			"destruction_time": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Time of final deletion",
			},
			"devicename": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Name of the device",
			},
			// "disk_path": {
			// 	Type:        schema.TypeString,
			// 	Computed:    true,
			// 	Description: "Disk path",
			// },
			// "guid": {
			// 	Type:        schema.TypeInt,
			// 	Computed:    true,
			// 	Description: "Disk ID on the storage side",
			// },
			"image_id": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Image ID",
			},
			"images": {
				Type:     schema.TypeList,
				Computed: true,
				Elem: &schema.Schema{
					Type: schema.TypeString,
				},
				Description: "IDs of images using the disk",
			},
			// "iqn": {
			// 	Type:        schema.TypeString,
			// 	Computed:    true,
			// 	Description: "Disk IQN",
			// },
			// "login": {
			// 	Type:        schema.TypeString,
			// 	Computed:    true,
			// 	Description: "Login to access the disk",
			// },
			// "milestones": {
			// 	Type:        schema.TypeInt,
			// 	Computed:    true,
			// 	Description: "Milestones",
			// },
			"order": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Disk order",
			},
			"params": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Disk params",
			},
			"parent_id": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "ID of the parent disk",
			},
			// "passwd": {
			// 	Type:        schema.TypeString,
			// 	Computed:    true,
			// 	Description: "Password to access the disk",
			// },
			"pci_slot": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "ID of the pci slot to which the disk is connected",
			},
			// "purge_attempts": {
			// 	Type:        schema.TypeInt,
			// 	Computed:    true,
			// 	Description: "Number of deletion attempts",
			// },
			"purge_time": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Time of the last deletion attempt",
			},
			"replication": {
				Type:     schema.TypeList,
				Computed: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"disk_id": {
							Type:     schema.TypeInt,
							Computed: true,
						},
						"pool_id": {
							Type:     schema.TypeString,
							Computed: true,
						},
						"role": {
							Type:     schema.TypeString,
							Computed: true,
						},
						"self_volume_id": {
							Type:     schema.TypeString,
							Computed: true,
						},
						"storage_id": {
							Type:     schema.TypeString,
							Computed: true,
						},
						"volume_id": {
							Type:     schema.TypeString,
							Computed: true,
						},
					},
				},
				Description: "Replication status",
			},
			// "reality_device_number": {
			// 	Type:        schema.TypeInt,
			// 	Computed:    true,
			// 	Description: "Reality device number",
			// },
			// "reference_id": {
			// 	Type:        schema.TypeString,
			// 	Computed:    true,
			// 	Description: "ID of the reference to the disk",
			// },
			"res_id": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Resource ID",
			},
			"res_name": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Name of the resource",
			},
			"role": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Disk role",
			},
			"sep_type": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Type SEP. Defines the type of storage system and contains one of the values set in the cloud platform",
			},
			"size_used": {
				Type:        schema.TypeFloat,
				Computed:    true,
				Description: "Number of used space, in GB",
			},
			"snapshots": {
				Type:     schema.TypeList,
				Computed: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"guid": {
							Type:        schema.TypeString,
							Computed:    true,
							Description: "ID of the snapshot",
						},
						"label": {
							Type:        schema.TypeString,
							Computed:    true,
							Description: "Name of the snapshot",
						},
						"res_id": {
							Type:        schema.TypeString,
							Computed:    true,
							Description: "Reference to the snapshot",
						},
						"snap_set_guid": {
							Type:        schema.TypeString,
							Computed:    true,
							Description: "The set snapshot ID",
						},
						"snap_set_time": {
							Type:        schema.TypeInt,
							Computed:    true,
							Description: "The set time of the snapshot",
						},
						"timestamp": {
							Type:        schema.TypeInt,
							Computed:    true,
							Description: "Snapshot time",
						},
					},
				},
			},
			"status": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Disk status",
			},
			"tech_status": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Technical status of the disk",
			},
			"vmid": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Virtual Machine ID (Deprecated)",
			},
		},
	}
}
