package schemas

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func MakeSchemaResourceLBBackend() map[string]schema.Attribute {
	return map[string]schema.Attribute{
		"lb_id": schema.Int64Attribute{
			Required: true,
		},
		"name": schema.StringAttribute{
			Required: true,
		},
		"algorithm": schema.StringAttribute{
			Optional: true,
			Computed: true,
			Validators: []validator.String{
				stringvalidator.OneOf("roundrobin", "static-rr", "leastconn"),
			},
		},
		"id": schema.StringAttribute{
			Computed: true,
			PlanModifiers: []planmodifier.String{
				stringplanmodifier.UseStateForUnknown(),
			},
		},
		"downinter": schema.Int64Attribute{
			Optional: true,
			Computed: true,
		},
		"fall": schema.Int64Attribute{
			Optional: true,
			Computed: true,
		},
		"inter": schema.Int64Attribute{
			Optional: true,
			Computed: true,
		},
		"maxconn": schema.Int64Attribute{
			Optional: true,
			Computed: true,
		},
		"maxqueue": schema.Int64Attribute{
			Optional: true,
			Computed: true,
		},
		"rise": schema.Int64Attribute{
			Optional: true,
			Computed: true,
		},
		"slowstart": schema.Int64Attribute{
			Optional: true,
			Computed: true,
		},
		"weight": schema.Int64Attribute{
			Optional: true,
			Computed: true,
		},
		"guid": schema.StringAttribute{
			Computed: true,
		},
		"servers": schema.ListNestedAttribute{
			Computed: true,
			NestedObject: schema.NestedAttributeObject{
				Attributes: map[string]schema.Attribute{
					"address": schema.StringAttribute{
						Computed: true,
					},
					"check": schema.StringAttribute{
						Computed: true,
					},
					"guid": schema.StringAttribute{
						Computed: true,
					},
					"name": schema.StringAttribute{
						Computed: true,
					},
					"port": schema.Int64Attribute{
						Computed: true,
					},
					"server_settings": schema.SingleNestedAttribute{
						Computed: true,
						Attributes: map[string]schema.Attribute{
							"downinter": schema.Int64Attribute{
								Computed: true,
							},
							"fall": schema.Int64Attribute{
								Computed: true,
							},
							"guid": schema.StringAttribute{
								Computed: true,
							},
							"inter": schema.Int64Attribute{
								Computed: true,
							},
							"maxconn": schema.Int64Attribute{
								Computed: true,
							},
							"maxqueue": schema.Int64Attribute{
								Computed: true,
							},
							"rise": schema.Int64Attribute{
								Computed: true,
							},
							"slowstart": schema.Int64Attribute{
								Computed: true,
							},
							"weight": schema.Int64Attribute{
								Computed: true,
							},
						},
					},
				},
			},
		},
	}
}
