package trunk

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

func dataSourceTrunkSchemaMake() map[string]*schema.Schema {
	log.Debugf("dataSourceTrunkSchemaMake: invoked")

	res := map[string]*schema.Schema{
		"trunk_id": {
			Type:        schema.TypeInt,
			Required:    true,
			Description: "trunk id",
		},
		"guid": {
			Type:        schema.TypeInt,
			Computed:    true,
			Description: "GUID",
		},
		"name": {
			Type:        schema.TypeString,
			Computed:    true,
			Description: "Name of the trunk",
		},
		"mac": {
			Type:        schema.TypeString,
			Computed:    true,
			Description: "MAC address",
		},
		"description": {
			Type:        schema.TypeString,
			Computed:    true,
			Description: "Description of the trunk",
		},
		"account_ids": {
			Type:     schema.TypeSet,
			Computed: true,
			Elem: &schema.Schema{
				Type: schema.TypeInt,
			},
			Description: "List of account IDs with access to this trunk",
		},
		"ovs_bridge": {
			Type:        schema.TypeString,
			Computed:    true,
			Description: "OVS bridge name",
		},
		"native_vlan_id": {
			Type:        schema.TypeInt,
			Computed:    true,
			Description: "Native VLAN ID",
		},
		"mtu": {
			Type:        schema.TypeInt,
			Computed:    true,
			Description: "Maximum Transmission Unit",
		},
		"status": {
			Type:        schema.TypeString,
			Computed:    true,
			Description: "if the trunk is enabled",
		},
		"trunk_tags": {
			Type:        schema.TypeString,
			Computed:    true,
			Description: "List of trunk tags (values between 1-4095)",
		},
		"created_at": {
			Type:        schema.TypeInt,
			Computed:    true,
			Description: "when the trunk was created",
		},
		"created_by": {
			Type:        schema.TypeString,
			Computed:    true,
			Description: "who created the trunk",
		},
		"updated_at": {
			Type:        schema.TypeInt,
			Computed:    true,
			Description: "when the trunk was updated",
		},
		"updated_by": {
			Type:        schema.TypeString,
			Computed:    true,
			Description: "who updated the trunk",
		},
		"deleted_at": {
			Type:        schema.TypeInt,
			Computed:    true,
			Description: "when the trunk was updated",
		},
		"deleted_by": {
			Type:        schema.TypeString,
			Computed:    true,
			Description: "who updated the trunk",
		},
	}

	return res
}

func dataSourceTrunkListSchemaMake() map[string]*schema.Schema {
	res := map[string]*schema.Schema{
		"trunk_ids": {
			Type:     schema.TypeList,
			Optional: true,
			Elem: &schema.Schema{
				Type: schema.TypeInt,
			},
			Description: "ID of the trunk(s) to filter by",
		},
		"account_ids": {
			Type:     schema.TypeList,
			Optional: true,
			Elem: &schema.Schema{
				Type: schema.TypeInt,
			},
			Description: "Account access ID(s) to filter by",
		},
		"trunk_tags": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: "Trunk tags to filter by (value between 1-4095)",
		},
		"page": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "Page number.",
		},
		"size": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "Page size.",
		},
		"status": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: "find by status",
		},
		"sort_by": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: "Sort by one of supported fields, format ±<field>",
		},
		"items": {
			Type:     schema.TypeList,
			Computed: true,
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"account_ids": {
						Type:     schema.TypeSet,
						Computed: true,
						Elem: &schema.Schema{
							Type: schema.TypeInt,
						},
						Description: "List of account IDs with access to this trunk",
					},
					"created_at": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "when the trunk was created",
					},
					"created_by": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "who created the trunk",
					},
					"deleted_at": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "when the trunk was updated",
					},
					"deleted_by": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "who updated the trunk",
					},
					"description": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "Description of the trunk",
					},
					"guid": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "GUID",
					},
					"id": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "Trunk ID",
					},
					"mac": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "MAC address",
					},
					"name": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "Name of the trunk",
					},
					"native_vlan_id": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "Native VLAN ID",
					},
					"ovs_bridge": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "OVS bridge name",
					},
					"mtu": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "Maximum Transmission Unit",
					},
					"status": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "if the trunk is enabled",
					},
					"trunk_tags": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "List of trunk tags (values between 1-4095)",
					},
					"updated_at": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "when the trunk was updated",
					},
					"updated_by": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "who updated the trunk",
					},
				},
			},
		},
		"entry_count": {
			Type:     schema.TypeInt,
			Computed: true,
		},
	}

	return res
}
