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"
)

type ResourceK8SCPModel struct {
	// request fields
	Name                   types.String   `tfsdk:"name"`
	RGID                   types.Int64    `tfsdk:"rg_id"`
	K8SCIID                types.Int64    `tfsdk:"k8sci_id"`
	NetworkPlugin          types.String   `tfsdk:"network_plugin"`
	SEPID                  types.Int64    `tfsdk:"sep_id"`
	SEPPool                types.String   `tfsdk:"sep_pool"`
	Num                    types.Int64    `tfsdk:"num"`
	CPU                    types.Int64    `tfsdk:"cpu"`
	Chipset                types.String   `tfsdk:"chipset"`
	RAM                    types.Int64    `tfsdk:"ram"`
	Disk                   types.Int64    `tfsdk:"disk"`
	ExtNetID               types.Int64    `tfsdk:"extnet_id"`
	VinsId                 types.Int64    `tfsdk:"vins_id"`
	WithLB                 types.Bool     `tfsdk:"with_lb"`
	HighlyAvailable        types.Bool     `tfsdk:"ha_mode"`
	AdditionalSANs         types.List     `tfsdk:"additional_sans"`
	InitConfiguration      types.String   `tfsdk:"init_config"`
	ClusterConfiguration   types.String   `tfsdk:"cluster_config"`
	KubeletConfiguration   types.String   `tfsdk:"kubelet_config"`
	KubeProxyConfiguration types.String   `tfsdk:"kube_proxy_config"`
	JoinConfiguration      types.String   `tfsdk:"join_config"`
	Description            types.String   `tfsdk:"desc"`
	ExtNetOnly             types.Bool     `tfsdk:"extnet_only"`
	OidcCertificate        types.String   `tfsdk:"oidc_cert"`
	Start                  types.Bool     `tfsdk:"start"`
	Enabled                types.Bool     `tfsdk:"enabled"`
	Permanently            types.Bool     `tfsdk:"permanently"`
	Restore                types.Bool     `tfsdk:"restore"`
	Timeouts               timeouts.Value `tfsdk:"timeouts"`
	LBSysctlParams         types.List     `tfsdk:"lb_sysctl_params"`
	// response fields
	Id              types.String `tfsdk:"id"`
	LastUpdated     types.String `tfsdk:"last_updated"`
	ACL             types.Object `tfsdk:"acl"`
	DetailedInfo    types.List   `tfsdk:"detailed_info"`
	AccountID       types.Int64  `tfsdk:"account_id"`
	AccountName     types.String `tfsdk:"account_name"`
	BServiceID      types.Int64  `tfsdk:"bservice_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"`
	K8SID           types.Int64  `tfsdk:"k8s_id"`
	K8CIName        types.String `tfsdk:"k8s_ci_name"`
	K8SAddressVIP   types.Object `tfsdk:"address_vip"`
	LBID            types.Int64  `tfsdk:"lb_id"`
	LBIP            types.String `tfsdk:"lb_ip"`
	MasterGroupId   types.Int64  `tfsdk:"master_group_id"`
	MasterGroupName types.String `tfsdk:"master_group_name"`
	RGName          types.String `tfsdk:"rg_name"`
	Status          types.String `tfsdk:"status"`
	TechStatus      types.String `tfsdk:"tech_status"`
	UpdatedBy       types.String `tfsdk:"updated_by"`
	UpdatedTime     types.Int64  `tfsdk:"updated_time"`
	Kubeconfig      types.String `tfsdk:"kubeconfig"`
}

type AddressVIPModel struct {
	BackendIP  types.String `tfsdk:"backend_ip"`
	FrontendIP types.String `tfsdk:"frontend_ip"`
}

type RecordACLModel struct {
	AccountACL types.List `tfsdk:"account_acl"`
	K8SACL     types.List `tfsdk:"k8s_acl"`
	RGACL      types.List `tfsdk:"rg_acl"`
}

type ItemACLModel struct {
	Explicit    types.Bool   `tfsdk:"explicit"`
	GUID        types.String `tfsdk:"guid"`
	Right       types.String `tfsdk:"right"`
	Status      types.String `tfsdk:"status"`
	Type        types.String `tfsdk:"type"`
	UserGroupID types.String `tfsdk:"user_group_id"`
}

type ItemDetailedInfoModel struct {
	ComputeId          types.Int64  `tfsdk:"compute_id"`
	Name               types.String `tfsdk:"name"`
	Status             types.String `tfsdk:"status"`
	TechStatus         types.String `tfsdk:"tech_status"`
	Interfaces         types.List   `tfsdk:"interfaces"`
	NatableVinsIp      types.String `tfsdk:"natable_vins_ip"`
	NatableVinsNetwork types.String `tfsdk:"natable_vins_network"`
}

type ItemInterfacesModel struct {
	DefGw     types.String `tfsdk:"def_gw"`
	IpAddress types.String `tfsdk:"ip_address"`
}

var AddressVIP map[string]attr.Type = map[string]attr.Type{
	"backend_ip":  types.StringType,
	"frontend_ip": types.StringType,
}

var ItemInterfaces map[string]attr.Type = map[string]attr.Type{
	"def_gw":     types.StringType,
	"ip_address": types.StringType,
}

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

var ItemAcl map[string]attr.Type = 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 ItemDetailedInfo map[string]attr.Type = map[string]attr.Type{
	"compute_id":           types.Int64Type,
	"name":                 types.StringType,
	"status":               types.StringType,
	"tech_status":          types.StringType,
	"interfaces":           types.ListType{ElemType: types.ObjectType{AttrTypes: ItemInterfaces}},
	"natable_vins_ip":      types.StringType,
	"natable_vins_network": types.StringType,
}
