package models

import (
	"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
	"github.com/hashicorp/terraform-plugin-framework/attr"
	"github.com/hashicorp/terraform-plugin-framework/types"
	disks "repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/disks/models"
)

type ResourceComputeModel struct {
	// required fields
	Name   types.String `tfsdk:"name"`
	RGID   types.Int64  `tfsdk:"rg_id"`
	Driver types.String `tfsdk:"driver"`
	CPU    types.Int64  `tfsdk:"cpu"`
	RAM    types.Int64  `tfsdk:"ram"`

	//optional fields
	ImageID                types.Int64  `tfsdk:"image_id"`
	WithoutBootDisk        types.Bool   `tfsdk:"without_boot_disk"`
	BootDiskSize           types.Int64  `tfsdk:"boot_disk_size"`
	AffinityLabel          types.String `tfsdk:"affinity_label"`
	AffinityRules          types.Set    `tfsdk:"affinity_rules"`
	AntiAffinityRules      types.Set    `tfsdk:"anti_affinity_rules"`
	AutoStartWithNode      types.Bool   `tfsdk:"auto_start_w_node"`
	CustomFields           types.String `tfsdk:"custom_fields"`
	Chipset                types.String `tfsdk:"chipset"`
	SepId                  types.Int64  `tfsdk:"sep_id"`
	Pool                   types.String `tfsdk:"pool"`
	ExtraDisks             types.Set    `tfsdk:"extra_disks"`
	Network                types.Set    `tfsdk:"network"`
	Tags                   types.Set    `tfsdk:"tags"`
	PortForwarding         types.Set    `tfsdk:"port_forwarding"`
	UserAccess             types.Set    `tfsdk:"user_access"`
	Snapshot               types.Set    `tfsdk:"snapshot"`
	PCIDevices             types.Set    `tfsdk:"pci_devices"`
	Rollback               types.Object `tfsdk:"rollback"`
	CDImageID              types.Int64  `tfsdk:"cd_image_id"`
	PinToStack             types.Bool   `tfsdk:"pin_to_stack"`
	PreferredCPU           types.List   `tfsdk:"preferred_cpu"`
	Description            types.String `tfsdk:"description"`
	CloudInit              types.String `tfsdk:"cloud_init"`
	Enabled                types.Bool   `tfsdk:"enabled"`
	Pause                  types.Bool   `tfsdk:"pause"`
	Reset                  types.Bool   `tfsdk:"reset"`
	Restore                types.Bool   `tfsdk:"restore"`
	ForceStop              types.Bool   `tfsdk:"force_stop"`
	ForceResize            types.Bool   `tfsdk:"force_resize"`
	Started                types.Bool   `tfsdk:"started"`
	DetachDisks            types.Bool   `tfsdk:"detach_disks"`
	Permanently            types.Bool   `tfsdk:"permanently"`
	IS                     types.String `tfsdk:"is"`
	IpaType                types.String `tfsdk:"ipa_type"`
	NumaAffinity           types.String `tfsdk:"numa_affinity"`
	CPUPin                 types.Bool   `tfsdk:"cpu_pin"`
	HPBacked               types.Bool   `tfsdk:"hp_backed"`
	LoaderType             types.String `tfsdk:"loader_type"`
	BootType               types.String `tfsdk:"boot_type"`
	HotResize              types.Bool   `tfsdk:"hot_resize"`
	NetworkInterfaceNaming types.String `tfsdk:"network_interface_naming"`
	SnapshotDeleteAsync    types.Bool   `tfsdk:"snapshot_delete_async"`

	// response fields
	ID                     types.String   `tfsdk:"id"`
	AccountId              types.Int64    `tfsdk:"account_id"`
	AccountName            types.String   `tfsdk:"account_name"`
	ACL                    types.Object   `tfsdk:"acl"` //k8s
	AffinityWeight         types.Int64    `tfsdk:"affinity_weight"`
	Architecture           types.String   `tfsdk:"arch"`
	BootOrder              types.List     `tfsdk:"boot_order"`
	BootDisk               types.Object   `tfsdk:"boot_disk"`
	BootDiskId             types.Int64    `tfsdk:"boot_disk_id"`
	CloneReference         types.Int64    `tfsdk:"clone_reference"`
	Clones                 types.List     `tfsdk:"clones"`
	ComputeCIID            types.Int64    `tfsdk:"computeci_id"`
	ComputeId              types.Int64    `tfsdk:"compute_id"`
	CreatedBy              types.String   `tfsdk:"created_by"`
	CreatedTime            types.Int64    `tfsdk:"created_time"`
	DeletedBy              types.String   `tfsdk:"deleted_by"`
	DeletedTime            types.Int64    `tfsdk:"deleted_time"`
	Devices                types.String   `tfsdk:"devices"`
	Disks                  types.List     `tfsdk:"disks"`
	GID                    types.Int64    `tfsdk:"gid"`
	GUID                   types.Int64    `tfsdk:"guid"`
	ImageName              types.String   `tfsdk:"image_name"`
	Interfaces             types.List     `tfsdk:"interfaces"`
	LockStatus             types.String   `tfsdk:"lock_status"`
	ManagerID              types.Int64    `tfsdk:"manager_id"`
	ManagerType            types.String   `tfsdk:"manager_type"`
	MigrationJob           types.Int64    `tfsdk:"migrationjob"`
	Milestones             types.Int64    `tfsdk:"milestones"`
	NatableVINSID          types.Int64    `tfsdk:"natable_vins_id"`
	NatableVINSIP          types.String   `tfsdk:"natable_vins_ip"`
	NatableVINSName        types.String   `tfsdk:"natable_vins_name"`
	NatableVINSNetwork     types.String   `tfsdk:"natable_vins_network"`
	NatableVINSNetworkName types.String   `tfsdk:"natable_vins_network_name"`
	NeedReboot             types.Bool     `tfsdk:"need_reboot"`
	NumaNodeId             types.Int64    `tfsdk:"numa_node_id"`
	OSUsers                types.List     `tfsdk:"os_users"`
	Pinned                 types.Bool     `tfsdk:"pinned"`
	ReferenceID            types.String   `tfsdk:"reference_id"`
	Registered             types.Bool     `tfsdk:"registered"`
	ResName                types.String   `tfsdk:"res_name"`
	ReservedNodeCpus       types.List     `tfsdk:"reserved_node_cpus"`
	RGName                 types.String   `tfsdk:"rg_name"`
	SnapSets               types.List     `tfsdk:"snap_sets"`
	StatelessSepID         types.Int64    `tfsdk:"stateless_sep_id"`
	StatelessSepType       types.String   `tfsdk:"stateless_sep_type"`
	Status                 types.String   `tfsdk:"status"`
	TechStatus             types.String   `tfsdk:"tech_status"`
	Timeouts               timeouts.Value `tfsdk:"timeouts"`
	UpdatedBy              types.String   `tfsdk:"updated_by"`
	UpdatedTime            types.Int64    `tfsdk:"updated_time"`
	UserManaged            types.Bool     `tfsdk:"user_managed"`
	Userdata               types.String   `tfsdk:"user_data"`
	VGPUs                  types.List     `tfsdk:"vgpus"`
	VirtualImageID         types.Int64    `tfsdk:"virtual_image_id"`
	VirtualImageName       types.String   `tfsdk:"virtual_image_name"`
	VNCPassword            types.String   `tfsdk:"vnc_password"`
}

type RecordResourceACLModel struct {
	AccountACL types.List `tfsdk:"account_acl"`
	ComputeACL types.List `tfsdk:"compute_acl"`
	RGACL      types.List `tfsdk:"rg_acl"`
}

type ItemResourceDiskModel struct {
	ACL                 types.String  `tfsdk:"acl"`
	AccountID           types.Int64   `tfsdk:"account_id"`
	BootPartition       types.Int64   `tfsdk:"boot_partition"`
	BusNumber           types.Int64   `tfsdk:"bus_number"`
	CreatedTime         types.Int64   `tfsdk:"created_time"`
	DeletedTime         types.Int64   `tfsdk:"deleted_time"`
	Description         types.String  `tfsdk:"desc"`
	DestructionTime     types.Int64   `tfsdk:"destruction_time"`
	DiskPath            types.String  `tfsdk:"disk_path"`
	GID                 types.Int64   `tfsdk:"gid"`
	GUID                types.Int64   `tfsdk:"guid"`
	ID                  types.Int64   `tfsdk:"disk_id"`
	ImageID             types.Int64   `tfsdk:"image_id"`
	Images              types.List    `tfsdk:"images"`
	IOTune              types.Object  `tfsdk:"iotune"`
	IQN                 types.String  `tfsdk:"iqn"`
	Login               types.String  `tfsdk:"login"`
	Milestones          types.Int64   `tfsdk:"milestones"`
	Name                types.String  `tfsdk:"name"`
	Order               types.Int64   `tfsdk:"order"`
	Params              types.String  `tfsdk:"params"`
	ParentID            types.Int64   `tfsdk:"parent_id"`
	Passwd              types.String  `tfsdk:"passwd"`
	PCISlot             types.Int64   `tfsdk:"pci_slot"`
	Pool                types.String  `tfsdk:"pool"`
	PresentTo           types.Map     `tfsdk:"present_to"`
	PurgeTime           types.Int64   `tfsdk:"purge_time"`
	ReferenceID         types.String  `tfsdk:"reference_id"`
	RealityDeviceNumber types.Int64   `tfsdk:"reality_device_number"`
	Replication         types.Object  `tfsdk:"replication"`
	ResID               types.String  `tfsdk:"res_id"`
	Role                types.String  `tfsdk:"role"`
	SepID               types.Int64   `tfsdk:"sep_id"`
	Shareable           types.Bool    `tfsdk:"shareable"`
	SizeMax             types.Int64   `tfsdk:"size_max"`
	SizeUsed            types.Float64 `tfsdk:"size_used"`
	Snapshots           types.List    `tfsdk:"snapshots"`
	Status              types.String  `tfsdk:"status"`
	TechStatus          types.String  `tfsdk:"tech_status"`
	Type                types.String  `tfsdk:"type"`
	VMID                types.Int64   `tfsdk:"vmid"`
}

type ItemPortForfardingModel struct {
	PublicPortStart types.Int64  `tfsdk:"public_port_start"`
	PublicPortEnd   types.Int64  `tfsdk:"public_port_end"`
	LocalPort       types.Int64  `tfsdk:"local_port"`
	Proto           types.String `tfsdk:"proto"`
}

type ItemNetworkModel struct {
	NetType   types.String `tfsdk:"net_type"`
	NetId     types.Int64  `tfsdk:"net_id"`
	IpAddress types.String `tfsdk:"ip_address"`
	Mac       types.String `tfsdk:"mac"`
	Weight    types.Int64  `tfsdk:"weight"`
	MTU       types.Int64  `tfsdk:"mtu"`
}

type ItemResourceInterfacesModel struct {
	BusNumber       types.Int64  `tfsdk:"bus_number"`
	ConnID          types.Int64  `tfsdk:"conn_id"`
	ConnType        types.String `tfsdk:"conn_type"`
	GetGW           types.String `tfsdk:"get_gw"`
	Enabled         types.Bool   `tfsdk:"enabled"`
	FLIPGroupID     types.Int64  `tfsdk:"flip_group_id"`
	GUID            types.String `tfsdk:"guid"`
	IPAddress       types.String `tfsdk:"ip_address"`
	ListenSSH       types.Bool   `tfsdk:"listen_ssh"`
	MAC             types.String `tfsdk:"mac"`
	MTU             types.Int64  `tfsdk:"mtu"`
	Name            types.String `tfsdk:"name"`
	NetID           types.Int64  `tfsdk:"net_id"`
	NetMask         types.Int64  `tfsdk:"netmask"`
	NetType         types.String `tfsdk:"net_type"`
	NodeID          types.Int64  `tfsdk:"node_id"`
	PCISlot         types.Int64  `tfsdk:"pci_slot"`
	QOS             types.Object `tfsdk:"qos"`
	LibvirtSettings types.Object `tfsdk:"libvirt_settings"`
	Target          types.String `tfsdk:"target"`
	Type            types.String `tfsdk:"type"`
	VNFs            types.List   `tfsdk:"vnfs"`
}

type ItemResourceRulesModel struct {
	Key      types.String `tfsdk:"key"`
	Mode     types.String `tfsdk:"mode"`
	Policy   types.String `tfsdk:"policy"`
	Topology types.String `tfsdk:"topology"`
	Value    types.String `tfsdk:"value"`
}

type ItemTagModel struct {
	Key   types.String `tfsdk:"key"`
	Value types.String `tfsdk:"value"`
}

type UserAccessModel struct {
	Username   types.String `tfsdk:"username"`
	AccessType types.String `tfsdk:"access_type"`
}

type ComputeVGPUModel struct {
	ID             types.Int64  `tfsdk:"id"`
	GID            types.Int64  `tfsdk:"gid"`
	Type           types.String `tfsdk:"type"`
	Mode           types.String `tfsdk:"mode"`
	Status         types.String `tfsdk:"status"`
	ProfileID      types.Int64  `tfsdk:"profile_id"`
	RAM            types.Int64  `tfsdk:"ram"`
	LastUpdateTime types.Int64  `tfsdk:"last_update_time"`
	CreatedTime    types.Int64  `tfsdk:"created_time"`
	DeletedTime    types.Int64  `tfsdk:"deleted_time"`
	VMID           types.Int64  `tfsdk:"vmid"`
	PGPUID         types.Int64  `tfsdk:"pgpuid"`
	ReferenceID    types.String `tfsdk:"reference_id"`
	AccountID      types.Int64  `tfsdk:"account_id"`
	RGID           types.Int64  `tfsdk:"rg_id"`
	LastClaimedBy  types.Int64  `tfsdk:"last_claimed_by"`
	PCISlot        types.Int64  `tfsdk:"pci_slot"`
	BusNumber      types.Int64  `tfsdk:"bus_number"`
	GUID           types.Int64  `tfsdk:"guid"`
}

var ItemNetwork = map[string]attr.Type{
	"net_type":   types.StringType,
	"net_id":     types.Int64Type,
	"ip_address": types.StringType,
	"mac":        types.StringType,
	"weight":     types.Int64Type,
	"mtu":        types.Int64Type,
}

var ItemDisk = map[string]attr.Type{
	"acl":                   types.StringType,
	"account_id":            types.Int64Type,
	"boot_partition":        types.Int64Type,
	"bus_number":            types.Int64Type,
	"created_time":          types.Int64Type,
	"deleted_time":          types.Int64Type,
	"desc":                  types.StringType,
	"destruction_time":      types.Int64Type,
	"disk_path":             types.StringType,
	"gid":                   types.Int64Type,
	"guid":                  types.Int64Type,
	"disk_id":               types.Int64Type,
	"image_id":              types.Int64Type,
	"images":                types.ListType{ElemType: types.Int64Type},
	"iotune":                types.ObjectType{AttrTypes: disks.ItemIOTune},
	"iqn":                   types.StringType,
	"login":                 types.StringType,
	"milestones":            types.Int64Type,
	"name":                  types.StringType,
	"order":                 types.Int64Type,
	"params":                types.StringType,
	"parent_id":             types.Int64Type,
	"passwd":                types.StringType,
	"pci_slot":              types.Int64Type,
	"pool":                  types.StringType,
	"present_to":            types.MapType{ElemType: types.Int64Type},
	"purge_time":            types.Int64Type,
	"replication":           types.ObjectType{AttrTypes: ItemReplication},
	"reality_device_number": types.Int64Type,
	"reference_id":          types.StringType,
	"res_id":                types.StringType,
	"role":                  types.StringType,
	"sep_id":                types.Int64Type,
	"shareable":             types.BoolType,
	"size_max":              types.Int64Type,
	"size_used":             types.Float64Type,
	"snapshots":             types.ListType{ElemType: types.ObjectType{AttrTypes: ItemSnapshot}},
	"status":                types.StringType,
	"tech_status":           types.StringType,
	"type":                  types.StringType,
	"vmid":                  types.Int64Type,
}

var ItemReplication = map[string]attr.Type{
	"disk_id":        types.Int64Type,
	"pool_id":        types.StringType,
	"role":           types.StringType,
	"self_volume_id": types.StringType,
	"storage_id":     types.StringType,
	"volume_id":      types.StringType,
}

var ItemSnapshot = map[string]attr.Type{
	"guid":          types.StringType,
	"label":         types.StringType,
	"reference_id":  types.StringType,
	"res_id":        types.StringType,
	"snap_set_guid": types.StringType,
	"snap_set_time": types.Int64Type,
	"timestamp":     types.Int64Type,
}

var ListACL = map[string]attr.Type{
	"account_acl": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemACL}},
	"compute_acl": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemACL}},
	"rg_acl":      types.ListType{ElemType: types.ObjectType{AttrTypes: ItemACL}},
}

var ItemACL = map[string]attr.Type{
	"explicit":      types.BoolType,
	"guid":          types.StringType,
	"right":         types.StringType,
	"status":        types.StringType,
	"type":          types.StringType,
	"user_group_id": types.StringType,
}

var ItemInterfaces = map[string]attr.Type{
	"bus_number":       types.Int64Type,
	"conn_id":          types.Int64Type,
	"conn_type":        types.StringType,
	"get_gw":           types.StringType,
	"enabled":          types.BoolType,
	"flip_group_id":    types.Int64Type,
	"guid":             types.StringType,
	"ip_address":       types.StringType,
	"listen_ssh":       types.BoolType,
	"mac":              types.StringType,
	"mtu":              types.Int64Type,
	"name":             types.StringType,
	"net_id":           types.Int64Type,
	"netmask":          types.Int64Type,
	"net_type":         types.StringType,
	"node_id":          types.Int64Type,
	"pci_slot":         types.Int64Type,
	"qos":              types.ObjectType{AttrTypes: ItemQos},
	"libvirt_settings": types.ObjectType{AttrTypes: ItemLibvirtSettings},
	"target":           types.StringType,
	"type":             types.StringType,
	"vnfs":             types.ListType{ElemType: types.Int64Type},
}

var ItemQos = map[string]attr.Type{
	"e_rate":   types.Int64Type,
	"guid":     types.StringType,
	"in_burst": types.Int64Type,
	"in_rate":  types.Int64Type,
}

var ItemLibvirtSettings = map[string]attr.Type{
	"guid":          types.StringType,
	"txmode":        types.StringType,
	"ioeventfd":     types.StringType,
	"event_idx":     types.StringType,
	"queues":        types.Int64Type,
	"rx_queue_size": types.Int64Type,
	"tx_queue_size": types.Int64Type,
}

var ItemOSUsers = map[string]attr.Type{
	"guid":       types.StringType,
	"login":      types.StringType,
	"password":   types.StringType,
	"public_key": types.StringType,
}

var ItemSnapSets = map[string]attr.Type{
	"disks":     types.ListType{ElemType: types.Int64Type},
	"guid":      types.StringType,
	"label":     types.StringType,
	"timestamp": types.Int64Type,
}

var ItemResourceRules = map[string]attr.Type{
	"key":      types.StringType,
	"mode":     types.StringType,
	"policy":   types.StringType,
	"topology": types.StringType,
	"value":    types.StringType,
}

var ItemTag = map[string]attr.Type{
	"key":   types.StringType,
	"value": types.StringType,
}

var ItemPortForfarding = map[string]attr.Type{
	"public_port_start": types.Int64Type,
	"public_port_end":   types.Int64Type,
	"local_port":        types.Int64Type,
	"proto":             types.StringType,
}

var ItemUserAccess = map[string]attr.Type{
	"username":    types.StringType,
	"access_type": types.StringType,
}

var ComputeItemVGPU = map[string]attr.Type{
	"id":               types.Int64Type,
	"gid":              types.Int64Type,
	"type":             types.StringType,
	"mode":             types.StringType,
	"status":           types.StringType,
	"profile_id":       types.Int64Type,
	"ram":              types.Int64Type,
	"last_update_time": types.Int64Type,
	"created_time":     types.Int64Type,
	"deleted_time":     types.Int64Type,
	"vmid":             types.Int64Type,
	"pgpuid":           types.Int64Type,
	"reference_id":     types.StringType,
	"account_id":       types.Int64Type,
	"rg_id":            types.Int64Type,
	"last_claimed_by":  types.Int64Type,
	"pci_slot":         types.Int64Type,
	"bus_number":       types.Int64Type,
	"guid":             types.Int64Type,
}
