package hypervisors

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

func resourceHypervisorSchemaMake() map[string]*schema.Schema {
	res := map[string]*schema.Schema{
		"name": {
			Type:     schema.TypeString,
			Required: true,
		},
		"display_name": {
			Type:     schema.TypeString,
			Required: true,
		},
		"hostname": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"ip": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"ports": {
			Type:     schema.TypeList,
			Computed: true,
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"data": {
						Type:     schema.TypeList,
						Computed: true,
						Elem: &schema.Resource{
							Schema: map[string]*schema.Schema{
								"id": {
									Type:     schema.TypeString,
									Computed: true,
								},
								"unique_identifier": {
									Type:     schema.TypeString,
									Computed: true,
								},
								"display_name": {
									Type:     schema.TypeString,
									Computed: true,
								},
								"up": {
									Type:     schema.TypeBool,
									Computed: true,
								},
							},
						},
					},
					"info": {
						Type:     schema.TypeList,
						Computed: true,
						Elem: &schema.Resource{
							Schema: map[string]*schema.Schema{
								"active_ports": {
									Type:     schema.TypeInt,
									Computed: true,
								},
								"total_ports": {
									Type:     schema.TypeInt,
									Computed: true,
								},
							},
						},
					},
				},
			},
		},
		"status": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"created_at": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"synced_at": {
			Type:     schema.TypeString,
			Computed: true,
		},
	}
	return res
}

func dataSourceHypervisorListSchemaMake() map[string]*schema.Schema {
	res := map[string]*schema.Schema{
		"page": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"per_page": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"sort_by": {
			Type:     schema.TypeString,
			Optional: true,
			ValidateFunc: validation.StringInSlice([]string{"name", "hostname", "last_sync",
				"display_name", "ip", "created_at", "updated_at"}, false),
		},
		"sort_order": {
			Type:         schema.TypeString,
			Optional:     true,
			ValidateFunc: validation.StringInSlice([]string{"asc", "desc"}, false),
		},
		"port_info": {
			Type:         schema.TypeString,
			Optional:     true,
			ValidateFunc: validation.StringInSlice([]string{"detailed", "general"}, false),
		},
		"hostname": {
			Type:     schema.TypeString,
			Optional: true,
		},
		"display_name": {
			Type:     schema.TypeString,
			Optional: true,
		},
		"ip": {
			Type:     schema.TypeString,
			Optional: true,
		},
		"created_from": {
			Type:     schema.TypeString,
			Optional: true,
		},
		"created_to": {
			Type:     schema.TypeString,
			Optional: true,
		},
		"updated_from": {
			Type:     schema.TypeString,
			Optional: true,
		},
		"updated_to": {
			Type:     schema.TypeString,
			Optional: true,
		},
		"items": {
			Type:        schema.TypeList,
			Computed:    true,
			Description: "List of hypervisors",
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"name": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"display_name": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"hostname": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"ip": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"ports": {
						Type:     schema.TypeList,
						Computed: true,
						Elem: &schema.Resource{
							Schema: map[string]*schema.Schema{
								"data": {
									Type:     schema.TypeList,
									Computed: true,
									Elem: &schema.Resource{
										Schema: map[string]*schema.Schema{
											"id": {
												Type:     schema.TypeString,
												Computed: true,
											},
											"unique_identifier": {
												Type:     schema.TypeString,
												Computed: true,
											},
											"display_name": {
												Type:     schema.TypeString,
												Computed: true,
											},
											"up": {
												Type:     schema.TypeBool,
												Computed: true,
											},
										},
									},
								},
								"info": {
									Type:     schema.TypeList,
									Computed: true,
									Elem: &schema.Resource{
										Schema: map[string]*schema.Schema{
											"active_ports": {
												Type:     schema.TypeInt,
												Computed: true,
											},
											"total_ports": {
												Type:     schema.TypeInt,
												Computed: true,
											},
										},
									},
								},
							},
						},
					},
					"status": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"created_at": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"synced_at": {
						Type:     schema.TypeString,
						Computed: true,
					},
				},
			},
		},
	}

	return res
}

func dataSourceHypervisorSchemaMake() map[string]*schema.Schema {
	res := map[string]*schema.Schema{
		"name": {
			Type:     schema.TypeString,
			Required: true,
		},
		"port_info": {
			Type:         schema.TypeString,
			Optional:     true,
			ValidateFunc: validation.StringInSlice([]string{"detailed", "general"}, false),
		},
		"display_name": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"hostname": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"ip": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"ports": {
			Type:     schema.TypeList,
			Computed: true,
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"data": {
						Type:     schema.TypeList,
						Computed: true,
						Elem: &schema.Resource{
							Schema: map[string]*schema.Schema{
								"id": {
									Type:     schema.TypeString,
									Computed: true,
								},
								"unique_identifier": {
									Type:     schema.TypeString,
									Computed: true,
								},
								"display_name": {
									Type:     schema.TypeString,
									Computed: true,
								},
								"up": {
									Type:     schema.TypeBool,
									Computed: true,
								},
							},
						},
					},
					"info": {
						Type:     schema.TypeList,
						Computed: true,
						Elem: &schema.Resource{
							Schema: map[string]*schema.Schema{
								"active_ports": {
									Type:     schema.TypeInt,
									Computed: true,
								},
								"total_ports": {
									Type:     schema.TypeInt,
									Computed: true,
								},
							},
						},
					},
				},
			},
		},
		"status": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"created_at": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"synced_at": {
			Type:     schema.TypeString,
			Computed: true,
		},
	}

	return res
}
