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/int64planmodifier"
	"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"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/validate"
)

func MakeSchemaResourceK8SWG() map[string]schema.Attribute {
	return map[string]schema.Attribute{
		// required attributes
		"k8s_id": schema.Int64Attribute{
			Required:    true,
			Description: "ID of k8s instance.",
		},
		"name": schema.StringAttribute{
			Required:    true,
			Description: "Name of the worker group.",
		},
		// optional attributes
		"num": schema.Int64Attribute{
			Optional:    true,
			Computed:    true,
			Description: "Number of worker nodes to create.",
		},
		"cpu": schema.Int64Attribute{
			Optional:    true,
			Computed:    true,
			Description: "Worker node CPU count.",
		},
		"chipset": schema.StringAttribute{
			Optional:    true,
			Description: "Type of the emulated system of work group",
			Validators: []validator.String{
				stringvalidator.OneOfCaseInsensitive("Q35", "i440fx"),
			},
		},
		"ram": schema.Int64Attribute{
			Optional:    true,
			Computed:    true,
			Description: "Worker node RAM in MB.",
			Validators: []validator.Int64{
				validate.DivisibleBy(constants.DivisibleByRAM),
			},
		},
		"disk": schema.Int64Attribute{
			Optional:    true,
			Computed:    true,
			Description: "Worker node boot disk size. If unspecified or 0, size is defined by OS image size.",
		},
		"labels": schema.ListAttribute{
			Optional:    true,
			Computed:    true,
			ElementType: types.StringType,
		},
		"annotations": schema.ListAttribute{
			Optional:    true,
			Computed:    true,
			ElementType: types.StringType,
		},
		"taints": schema.ListAttribute{
			Optional:    true,
			Computed:    true,
			ElementType: types.StringType,
		},
		"worker_sep_id": schema.Int64Attribute{
			Optional: true,
		},
		"worker_sep_pool": schema.StringAttribute{
			Optional: true,
		},
		"cloud_init": schema.StringAttribute{
			Optional: true,
		},
		// computed attributes
		"id": schema.StringAttribute{
			Computed: true,
			PlanModifiers: []planmodifier.String{
				stringplanmodifier.UseStateForUnknown(),
			},
		},
		"last_updated": schema.StringAttribute{
			Computed:    true,
			Description: "Timestamp of the last Terraform update of the order.",
		},
		"wg_id": schema.Int64Attribute{
			Computed: true,
			PlanModifiers: []planmodifier.Int64{
				int64planmodifier.UseStateForUnknown(),
			},
		},
		"detailed_info": schema.ListNestedAttribute{
			Computed: true,
			NestedObject: schema.NestedAttributeObject{
				Attributes: map[string]schema.Attribute{
					"compute_id": schema.Int64Attribute{
						Computed: true,
					},
					"name": schema.StringAttribute{
						Computed: true,
					},
					"status": schema.StringAttribute{
						Computed: true,
					},
					"tech_status": schema.StringAttribute{
						Computed: true,
					},
					"interfaces": schema.ListNestedAttribute{
						Computed: true,
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"def_gw": schema.StringAttribute{
									Computed: true,
								},
								"ip_address": schema.StringAttribute{
									Computed: true,
								},
							},
						},
					},
					"natable_vins_ip": schema.StringAttribute{
						Computed: true,
					},
					"natable_vins_network": schema.StringAttribute{
						Computed: true,
					},
				},
			},
		},
		"guid": schema.StringAttribute{
			Computed: true,
		},
	}
}
