package defaultsecuritypolicy

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

func dataSourceDefaultSecurityPolicyListSchemaMake() map[string]*schema.Schema {
	res := map[string]*schema.Schema{
		"access_group_id": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: "id of the access group",
		},
		"page": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "result page number",
		},
		"per_page": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "number of results per page",
		},
		"sort_by": {
			Type:         schema.TypeString,
			Optional:     true,
			ValidateFunc: validation.StringInSlice([]string{"created_at", "updated_at"}, false),
			Description:  "sort by one of the supported fields",
		},
		"sort_order": {
			Type:         schema.TypeString,
			Optional:     true,
			ValidateFunc: validation.StringInSlice([]string{"asc", "desc"}, false),
			Description:  "sorting order",
		},
		"items": {
			Type:        schema.TypeList,
			Computed:    true,
			Description: "List of default security policies",
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"access_group_id": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "Access group ID",
					},
					"created_at": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "Creation timestamp",
					},
					"default_acl_drop": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "Default ACL drop action",
					},
					"default_open_session_drop": {
						Type:        schema.TypeBool,
						Computed:    true,
						Description: "Default open session drop flag",
					},
					"description": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "Description",
					},
					"display_name": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "Display name",
					},
					"id": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "Unique identifier",
					},
					"security_rules": {
						Type:        schema.TypeList,
						Computed:    true,
						Description: "Security rules",
						Elem: &schema.Resource{
							Schema: map[string]*schema.Schema{
								"access_group_id": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Access group ID",
								},
								"action": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Action",
								},
								"description": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Description",
								},
								"destination_net_object": {
									Type:        schema.TypeList,
									Computed:    true,
									Description: "Destination network object",
									Elem: &schema.Resource{
										Schema: map[string]*schema.Schema{
											"display_name": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Display name",
											},
											"net_address_pool_id": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Network address pool ID",
											},
											"net_object_group_id": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Network object group ID",
											},
										},
									},
								},
								"direction": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Direction",
								},
								"display_name": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Display name",
								},
								"enabled": {
									Type:        schema.TypeBool,
									Computed:    true,
									Description: "Enabled flag",
								},
								"filter": {
									Type:        schema.TypeList,
									Computed:    true,
									Description: "Filter configuration",
									Elem: &schema.Resource{
										Schema: map[string]*schema.Schema{
											"filters": {
												Type:        schema.TypeList,
												Computed:    true,
												Description: "Filter parameters",
												Elem: &schema.Resource{
													Schema: map[string]*schema.Schema{
														"all": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "All protocols flag",
														},
														"arp": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "ARP protocol flag",
														},
														"dhcp": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "DHCP protocol flag",
														},
														"expression": {
															Type:        schema.TypeString,
															Computed:    true,
															Description: "Filter expression",
														},
														"icmp": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "ICMP protocol flag",
														},
														"ip": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "IP protocol flag",
														},
														"ip_v4": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "IPv4 protocol flag",
														},
														"ip_v6": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "IPv6 protocol flag",
														},
														"keep_opened_sessions": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "Keep opened sessions flag",
														},
														"nd": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "ND protocol flag",
														},
														"tcp": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "TCP protocol flag",
														},
														"tcp_dst_ports": {
															Type:        schema.TypeList,
															Computed:    true,
															Description: "TCP destination ports",
															Elem: &schema.Schema{
																Type: schema.TypeString,
															},
														},
														"udp": {
															Type:        schema.TypeBool,
															Computed:    true,
															Description: "UDP protocol flag",
														},
														"udp_dst_ports": {
															Type:        schema.TypeList,
															Computed:    true,
															Description: "UDP destination ports",
															Elem: &schema.Schema{
																Type: schema.TypeString,
															},
														},
													},
												},
											},
											"name": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Filter name",
											},
										},
									},
								},
								"id": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Unique identifier",
								},
								"log_enabled": {
									Type:        schema.TypeBool,
									Computed:    true,
									Description: "Log enabled flag",
								},
								"log_name": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Log name",
								},
								"log_severity": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Log severity",
								},
								"priority": {
									Type:        schema.TypeInt,
									Computed:    true,
									Description: "Priority",
								},
								"security_policy_id": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Security policy ID",
								},
								"source_net_object": {
									Type:        schema.TypeList,
									Computed:    true,
									Description: "Source network object",
									Elem: &schema.Resource{
										Schema: map[string]*schema.Schema{
											"display_name": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Display name",
											},
											"net_address_pool_id": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Network address pool ID",
											},
											"net_object_group_id": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Network object group ID",
											},
										},
									},
								},
								"statistics_enabled": {
									Type:        schema.TypeBool,
									Computed:    true,
									Description: "Statistics enabled flag",
								},
								"version_id": {
									Type:        schema.TypeInt,
									Computed:    true,
									Description: "Version ID",
								},
							},
						},
					},
					"locked_at": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "Locked timestamp",
					},
					"status": {
						Type:        schema.TypeList,
						Computed:    true,
						Description: "Status information",
						Elem: &schema.Resource{
							Schema: map[string]*schema.Schema{
								"common": {
									Type:        schema.TypeString,
									Computed:    true,
									Description: "Common status",
								},
								"hypervisors": {
									Type:        schema.TypeList,
									Computed:    true,
									Description: "Hypervisor statuses",
									Elem: &schema.Resource{
										Schema: map[string]*schema.Schema{
											"status": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Status",
											},
											"name": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Name",
											},
											"display_name": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Display name",
											},
											"hypervisor_status": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Hypervisor status",
											},
											"synced_at": {
												Type:        schema.TypeString,
												Computed:    true,
												Description: "Last sync timestamp",
											},
										},
									},
								},
							},
						},
					},
					"version_id": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "Version ID",
					},
				},
			},
		},
	}

	return res
}

