package k8s

import (
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceK8sCPSchemaV1() *schema.Resource {
	return &schema.Resource{
		Schema: map[string]*schema.Schema{
			"name": {
				Type:        schema.TypeString,
				Required:    true,
				Description: "Name of the cluster.",
			},
			"rg_id": {
				Type:     schema.TypeInt,
				Required: true,
				//ForceNew:    true,
				Description: "Resource group ID that this instance belongs to.",
			},
			"k8sci_id": {
				Type:     schema.TypeInt,
				Required: true,
				//ForceNew:    true,
				Description: "ID of the k8s catalog item to base this instance on.",
			},
			"network_plugin": {
				Type:         schema.TypeString,
				Required:     true,
				Description:  "Network plugin to be used",
				ValidateFunc: validation.StringInSlice([]string{"flannel", "weavenet", "calico"}, true),
			},
			"num": {
				Type:         schema.TypeInt,
				Optional:     true,
				Computed:     true,
				ValidateFunc: validation.IntInSlice([]int{1, 3}),
				Description:  "Number of VMs to create. Can be either 1 or 3",
			},
			"cpu": {
				Type:        schema.TypeInt,
				Optional:    true,
				Computed:    true,
				Description: "Node CPU count.",
			},
			"ram": {
				Type:        schema.TypeInt,
				Optional:    true,
				Computed:    true,
				Description: "Node RAM in MB.",
			},
			"disk": {
				Type:        schema.TypeInt,
				Optional:    true,
				Computed:    true,
				Description: "Node boot disk size in GB.",
			},
			"sep_id": {
				Type:        schema.TypeInt,
				Optional:    true,
				Computed:    true,
				Description: "Storage Endpoint ID",
			},
			"sep_pool": {
				Type:        schema.TypeString,
				Optional:    true,
				Computed:    true,
				Description: "Storage Endpoint Pool",
			},
			"with_lb": {
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     true,
				Description: "Create k8s with load balancer if true.",
			},
			"extnet_only": {
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     false,
				Description: "Use only selected ExtNet for infrastructure connections",
			},
			// /4.4.0
			"cloud_init": {
				Type:        schema.TypeString,
				Optional:    true,
				Description: "Meta data for working group computes, format YAML 'user_data': 1111",
			},
			"join_config": {
				Type:        schema.TypeString,
				Optional:    true,
				Description: "is used to configure the behavior and settings for joining a node to a cluster. It includes parameters such as the cluster's control plane endpoint, token, and certificate key. insert a valid JSON string with all levels of nesting.",
			},
			"kube_proxy_config": {
				Type:        schema.TypeString,
				Optional:    true,
				Description: "is used to configure the behavior and settings of the Kube-proxy, which is responsible for network proxying and load balancing within the cluster. It includes parameters such as proxy mode, cluster IP ranges, and other Kube-proxy specific configurations. insert a valid JSON string with all levels of nesting.",
			},
			"kubelet_config": {
				Type:        schema.TypeString,
				Optional:    true,
				Description: "is used to configure the behavior and settings of the Kubelet, which is the primary node agent that runs on each node in the cluster. It includes parameters such as node IP address, resource allocation, pod eviction policies, and other Kubelet-specific configurations. insert a valid JSON string with all levels of nesting.",
			},
			"cluster_config": {
				Type:        schema.TypeString,
				Optional:    true,
				Description: "is used to define global settings and configurations for the entire cluster. It includes parameters such as cluster name, DNS settings, authentication methods, and other cluster-wide configurations. insert a valid JSON string with all levels of nesting.",
			},
			"init_config": {
				Type:        schema.TypeString,
				Optional:    true,
				Description: "is used to define settings and actions that should be performed before any other component in the cluster starts. It allows you to configure things like node registration, network setup, and other initialization tasks. insert a valid JSON string with all levels of nesting.",
			},
			"additional_sans": {
				Type:        schema.TypeList,
				Optional:    true,
				Description: "Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names",
				Elem: &schema.Schema{
					Type: schema.TypeString,
				},
			},
			"ha_mode": {
				Type:        schema.TypeBool,
				Optional:    true,
				Description: "Use Highly Available schema for LB deploy",
			},
			"lb_sysctl_params": {
				Type:        schema.TypeString,
				Optional:    true,
				Description: "Custom sysctl values for Load Balancer instance. Applied on boot.",
			},
			"oidc_cert": {
				Type:        schema.TypeString,
				Optional:    true,
				Description: "insert ssl certificate in x509 pem format",
			},
			////
			"extnet_id": {
				Type:     schema.TypeInt,
				Optional: true,
				Computed: true,
				//ForceNew:    true,
				Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
			},
			"desc": {
				Type:        schema.TypeString,
				Optional:    true,
				Description: "Text description of this instance.",
			},
			"start": {
				Type:        schema.TypeBool,
				Optional:    true,
				Default:     true,
				Description: "Start k8s cluster.",
			},
			"detailed_info": {
				Type:     schema.TypeList,
				Computed: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"compute_id": {
							Type:     schema.TypeInt,
							Computed: true,
						},
						"name": {
							Type:     schema.TypeString,
							Computed: true,
						},
						"status": {
							Type:     schema.TypeString,
							Computed: true,
						},
						"tech_status": {
							Type:     schema.TypeString,
							Computed: true,
						},
						"interfaces": {
							Type:     schema.TypeList,
							Computed: true,
							Elem: &schema.Resource{
								Schema: map[string]*schema.Schema{
									"def_gw": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"ip_address": {
										Type:     schema.TypeString,
										Computed: true,
									},
								},
							},
						},
						"natable_vins_ip": {
							Type:     schema.TypeString,
							Computed: true,
						},
						"natable_vins_network": {
							Type:     schema.TypeString,
							Computed: true,
						},
					},
				},
			},
			"master_id": {
				Type:        schema.TypeInt,
				Computed:    true,
				Description: "Master group ID.",
			},
			"master_name": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Master group name.",
			},
			"acl": {
				Type:     schema.TypeList,
				Computed: true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"account_acl": {
							Type:     schema.TypeList,
							Computed: true,
							Elem: &schema.Resource{
								Schema: map[string]*schema.Schema{
									"explicit": {
										Type:     schema.TypeBool,
										Computed: true,
									},
									"guid": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"right": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"status": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"type": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"user_group_id": {
										Type:     schema.TypeString,
										Computed: true,
									},
								},
							},
						},
						"k8s_acl": {
							Type:     schema.TypeList,
							Computed: true,
							Elem: &schema.Resource{
								Schema: map[string]*schema.Schema{
									"explicit": {
										Type:     schema.TypeBool,
										Computed: true,
									},
									"guid": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"right": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"status": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"type": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"user_group_id": {
										Type:     schema.TypeString,
										Computed: true,
									},
								},
							},
						},
						"rg_acl": {
							Type:     schema.TypeList,
							Computed: true,
							Elem: &schema.Resource{
								Schema: map[string]*schema.Schema{
									"explicit": {
										Type:     schema.TypeBool,
										Computed: true,
									},
									"guid": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"right": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"status": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"type": {
										Type:     schema.TypeString,
										Computed: true,
									},
									"user_group_id": {
										Type:     schema.TypeString,
										Computed: true,
									},
								},
							},
						},
					},
				},
			},
			"account_id": {
				Type:     schema.TypeInt,
				Computed: true,
			},
			"account_name": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"bservice_id": {
				Type:     schema.TypeInt,
				Computed: true,
			},
			"created_by": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"created_time": {
				Type:     schema.TypeInt,
				Computed: true,
			},
			"deleted_by": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"deleted_time": {
				Type:     schema.TypeInt,
				Computed: true,
			},
			"k8s_ci_name": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"lb_id": {
				Type:     schema.TypeInt,
				Computed: true,
			},
			"k8s_id": {
				Type:     schema.TypeInt,
				Computed: true,
			},
			"lb_ip": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "IP address of default load balancer.",
			},
			"rg_name": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"status": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"tech_status": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"updated_by": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"updated_time": {
				Type:     schema.TypeInt,
				Computed: true,
			},
			"kubeconfig": {
				Type:        schema.TypeString,
				Computed:    true,
				Description: "Kubeconfig for cluster access.",
			},
			"vins_id": {
				Type:        schema.TypeInt,
				Optional:    true,
				Computed:    true,
				Description: "ID of default vins for this instace.",
			},
		},
	}
}
