package models

import (
	"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
	"github.com/hashicorp/terraform-plugin-framework/attr"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

type DataSourceLB struct {
	// required fields
	Timeouts timeouts.Value `tfsdk:"timeouts"`
	LBID     types.Int64    `tfsdk:"lb_id"`

	// response fields
	HAMode        types.Bool   `tfsdk:"ha_mode"`
	ACL           types.String `tfsdk:"acl"`
	BackendHAIP   types.String `tfsdk:"backend_haip"`
	Backends      types.List   `tfsdk:"backends"`
	CKey          types.String `tfsdk:"ckey"`
	Description   types.String `tfsdk:"desc"`
	DPAPIUser     types.String `tfsdk:"dp_api_user"`
	DPAPIPassword types.String `tfsdk:"dp_api_password"`
	ExtNetID      types.Int64  `tfsdk:"extnet_id"`
	FrontendHAIP  types.String `tfsdk:"frontend_haip"`
	Frontends     types.List   `tfsdk:"frontends"`
	GID           types.Int64  `tfsdk:"gid"`
	GUID          types.Int64  `tfsdk:"guid"`
	ID            types.Int64  `tfsdk:"id"`
	ImageID       types.Int64  `tfsdk:"image_id"`
	ManagerId     types.Int64  `tfsdk:"manager_id"`
	ManagerType   types.String `tfsdk:"manager_type"`
	Meta          types.List   `tfsdk:"meta"`
	Milestones    types.Int64  `tfsdk:"milestones"`
	Name          types.String `tfsdk:"name"`
	PartK8s       types.Bool   `tfsdk:"part_k8s"`
	PrimaryNode   types.Object `tfsdk:"primary_node"`
	RGID          types.Int64  `tfsdk:"rg_id"`
	SecondaryNode types.Object `tfsdk:"secondary_node"`
	Status        types.String `tfsdk:"status"`
	TechStatus    types.String `tfsdk:"tech_status"`
	UserManaged   types.Bool   `tfsdk:"user_managed"`
	VINSID        types.Int64  `tfsdk:"vins_id"`
}

type ItemBackendModel struct {
	Algorithm             types.String `tfsdk:"algorithm"`
	GUID                  types.String `tfsdk:"guid"`
	Name                  types.String `tfsdk:"name"`
	ServerDefaultSettings types.Object `tfsdk:"server_default_settings"`
	Servers               types.List   `tfsdk:"servers"`
}

type ItemFrontendModel struct {
	Backend  types.String `tfsdk:"backend"`
	Bindings types.List   `tfsdk:"bindings"`
	GUID     types.String `tfsdk:"guid"`
	Name     types.String `tfsdk:"name"`
}

type RecordNodeModel struct {
	BackendIP  types.String `tfsdk:"backend_ip"`
	ComputeID  types.Int64  `tfsdk:"compute_id"`
	FrontendIP types.String `tfsdk:"frontend_ip"`
	GUID       types.String `tfsdk:"guid"`
	MGMTIP     types.String `tfsdk:"mgmt_ip"`
	NetworkID  types.Int64  `tfsdk:"network_id"`
}

type RecordServerSettingsModel struct {
	Inter     types.Int64  `tfsdk:"inter"`
	GUID      types.String `tfsdk:"guid"`
	DownInter types.Int64  `tfsdk:"downinter"`
	Rise      types.Int64  `tfsdk:"rise"`
	Fall      types.Int64  `tfsdk:"fall"`
	SlowStart types.Int64  `tfsdk:"slowstart"`
	MaxConn   types.Int64  `tfsdk:"maxconn"`
	MaxQueue  types.Int64  `tfsdk:"maxqueue"`
	Weight    types.Int64  `tfsdk:"weight"`
}

type RecordServerModel struct {
	Address        types.String `tfsdk:"address"`
	Check          types.String `tfsdk:"check"`
	GUID           types.String `tfsdk:"guid"`
	Name           types.String `tfsdk:"name"`
	Port           types.Int64  `tfsdk:"port"`
	ServerSettings types.Object `tfsdk:"server_settings"`
}

type ItemBindingModel struct {
	Address types.String `tfsdk:"address"`
	GUID    types.String `tfsdk:"guid"`
	Name    types.String `tfsdk:"name"`
	Port    types.Int64  `tfsdk:"port"`
}

var ItemNode = map[string]attr.Type{
	"backend_ip":  types.StringType,
	"compute_id":  types.Int64Type,
	"frontend_ip": types.StringType,
	"guid":        types.StringType,
	"mgmt_ip":     types.StringType,
	"network_id":  types.Int64Type,
}

var ItemBackend = map[string]attr.Type{
	"algorithm":               types.StringType,
	"guid":                    types.StringType,
	"name":                    types.StringType,
	"server_default_settings": types.ObjectType{AttrTypes: ItemServerSettings},
	"servers":                 types.ListType{ElemType: types.ObjectType{AttrTypes: ItemServers}},
}

var ItemFrontend = map[string]attr.Type{
	"backend":  types.StringType,
	"bindings": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemBindings}},
	"guid":     types.StringType,
	"name":     types.StringType,
}

var ItemServers = map[string]attr.Type{
	"address":         types.StringType,
	"check":           types.StringType,
	"guid":            types.StringType,
	"name":            types.StringType,
	"port":            types.Int64Type,
	"server_settings": types.ObjectType{AttrTypes: ItemServerSettings},
}

var ItemServerSettings = map[string]attr.Type{
	"inter":     types.Int64Type,
	"guid":      types.StringType,
	"downinter": types.Int64Type,
	"rise":      types.Int64Type,
	"fall":      types.Int64Type,
	"slowstart": types.Int64Type,
	"maxconn":   types.Int64Type,
	"maxqueue":  types.Int64Type,
	"weight":    types.Int64Type,
}

var ItemBindings = map[string]attr.Type{
	"address": types.StringType,
	"name":    types.StringType,
	"port":    types.Int64Type,
	"guid":    types.StringType,
}
