package schemas

import (
	"github.com/hashicorp/terraform-plugin-framework/resource/schema"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func MakeSchemaResourceDisk() map[string]schema.Attribute {
	return map[string]schema.Attribute{
		// required attributes
		"account_id": schema.Int64Attribute{
			Required:    true,
			Description: "ID of the account",
		},
		"disk_name": schema.StringAttribute{
			Required:    true,
			Description: "Iname of disk",
		},
		"size_max": schema.Int64Attribute{
			Required:    true,
			Description: "size in GB, default is 10",
		},

		// optional attributes
		"desc": schema.StringAttribute{
			Optional:    true,
			Computed:    true,
			Description: "description of disk",
		},
		"pool": schema.StringAttribute{
			Optional:    true,
			Computed:    true,
			Description: "Pool for disk location",
		},
		"sep_id": schema.Int64Attribute{
			Optional:    true,
			Computed:    true,
			Description: "Storage endpoint provider ID to create disk",
		},
		"type": schema.StringAttribute{
			Computed:    true,
			Description: "(B;D;T) B=Boot;D=Data;T=Temp",
			// default is D
		},
		"detach": schema.BoolAttribute{
			Optional:    true,
			Computed:    true,
			Description: "Detaching the disk from compute",
			Default:     booldefault.StaticBool(true),
		},
		"permanently": schema.BoolAttribute{
			Optional:    true,
			Computed:    true,
			Description: "Whether to completely delete the disk, works only with non attached disks",
			Default:     booldefault.StaticBool(true),
		},
		"shareable": schema.BoolAttribute{
			Optional:    true,
			Computed:    true,
			Description: "share disk",
		},
		"iotune": schema.SingleNestedAttribute{
			Optional: true,
			Computed: true,
			Attributes: map[string]schema.Attribute{
				"read_bytes_sec": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Number of bytes to read per second",
				},
				"read_bytes_sec_max": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Maximum number of bytes to read",
				},
				"read_iops_sec": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Number of io read operations per second",
				},
				"read_iops_sec_max": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Maximum number of io read operations",
				},
				"size_iops_sec": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Size of io operations",
				},
				"total_bytes_sec": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Total size bytes per second",
				},
				"total_bytes_sec_max": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Maximum total size of bytes per second",
				},
				"total_iops_sec": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Total number of io operations per second",
				},
				"total_iops_sec_max": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Maximum total number of io operations per second",
				},
				"write_bytes_sec": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Number of bytes to write per second",
				},
				"write_bytes_sec_max": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Maximum number of bytes to write per second",
				},
				"write_iops_sec": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Number of write operations per second",
				},
				"write_iops_sec_max": schema.Int64Attribute{
					Optional:    true,
					Computed:    true,
					Description: "Maximum number of write operations per second",
				},
			},
		},

		// computed attributes
		"id": schema.StringAttribute{
			Computed: true,
			PlanModifiers: []planmodifier.String{
				stringplanmodifier.UseStateForUnknown(),
			},
		},
		"disk_id": schema.Int64Attribute{
			Computed: true,
		},
		"account_name": schema.StringAttribute{
			Computed: true,
		},
		"acl": schema.StringAttribute{
			Computed: true,
		},
		"computes": schema.ListNestedAttribute{
			Computed: true,
			NestedObject: schema.NestedAttributeObject{
				Attributes: map[string]schema.Attribute{
					"compute_id": schema.StringAttribute{
						Computed: true,
					},
					"compute_name": schema.StringAttribute{
						Computed: true,
					},
				},
			},
		},
		"created_by": schema.StringAttribute{
			Computed: true,
		},
		"created_time": schema.Int64Attribute{
			Computed: true,
		},
		"deleted_by": schema.StringAttribute{
			Computed: true,
		},
		"deleted_time": schema.Int64Attribute{
			Computed: true,
		},
		"destruction_time": schema.Int64Attribute{
			Computed: true,
		},
		"devicename": schema.StringAttribute{
			Computed: true,
		},
		"image_id": schema.Int64Attribute{
			Computed: true,
		},
		"images": schema.ListAttribute{
			Computed:    true,
			ElementType: types.Int64Type,
		},
		"gid": schema.Int64Attribute{
			Computed:    true,
			Description: "ID of the grid (platform)",
		},
		"last_updated": schema.StringAttribute{
			Computed:    true,
			Description: "Timestamp of the last Terraform update of the disk resource.",
		},
		"machine_id": schema.Int64Attribute{
			Computed: true,
		},
		"machine_name": schema.StringAttribute{
			Computed: true,
		},
		"order": schema.Int64Attribute{
			Computed: true,
		},
		"params": schema.StringAttribute{
			Computed: true,
		},
		"parent_id": schema.Int64Attribute{
			Computed: true,
		},
		"pci_slot": schema.Int64Attribute{
			Computed: true,
		},
		"present_to": schema.MapAttribute{
			Computed:    true,
			ElementType: types.Int64Type,
		},
		"purge_time": schema.Int64Attribute{
			Computed: true,
		},
		"res_id": schema.StringAttribute{
			Computed: true,
		},
		"res_name": schema.StringAttribute{
			Computed: true,
		},
		"role": schema.StringAttribute{
			Computed: true,
		},
		"sep_type": schema.StringAttribute{
			Computed: true,
		},
		"size_used": schema.Float64Attribute{
			Computed: true,
		},
		"snapshots": schema.ListNestedAttribute{
			Computed: true,
			NestedObject: schema.NestedAttributeObject{
				Attributes: map[string]schema.Attribute{
					"guid": schema.StringAttribute{
						Computed: true,
					},
					"label": schema.StringAttribute{
						Computed: true,
					},
					"res_id": schema.StringAttribute{
						Computed: true,
					},
					"snap_set_guid": schema.StringAttribute{
						Computed: true,
					},
					"snap_set_time": schema.Int64Attribute{
						Computed: true,
					},
					"timestamp": schema.Int64Attribute{
						Computed: true,
					},
				},
			},
		},
		"status": schema.StringAttribute{
			Computed: true,
		},
		"tech_status": schema.StringAttribute{
			Computed: true,
		},
		"updated_by": schema.StringAttribute{
			Computed: true,
		},
		"updated_time": schema.Int64Attribute{
			Computed: true,
		},
		"vmid": schema.Int64Attribute{
			Computed: true,
		},
	}
}
