package audit

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

func dataSourceAuditSchemaMake() map[string]*schema.Schema {
	return map[string]*schema.Schema{
		"audit_guid": {
			Type:        schema.TypeString,
			Required:    true,
			Description: "audit guid",
		},

		"args": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"call": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"correlation_id": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"guid": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"kwargs": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"remote_addr": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"responsetime": {
			Type:     schema.TypeFloat,
			Computed: true,
		},
		"result": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"status_code": {
			Type:     schema.TypeInt,
			Computed: true,
		},
		"timestamp": {
			Type:     schema.TypeFloat,
			Computed: true,
		},
		"timestamp_end": {
			Type:     schema.TypeFloat,
			Computed: true,
		},
		"ttl": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"user": {
			Type:     schema.TypeString,
			Computed: true,
		},
		"resgroup_id": {
			Type:     schema.TypeInt,
			Computed: true,
		},
		"account_id": {
			Type:     schema.TypeInt,
			Computed: true,
		},
		"compute_id": {
			Type:     schema.TypeInt,
			Computed: true,
		},
	}
}

func dataSourceAuditListSchemaMake() map[string]*schema.Schema {
	return map[string]*schema.Schema{
		"timestamp_at": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "find all audits after point in time (unixtime)",
		},
		"timestamp_to": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "find all audits before point in time (unixtime)",
		},
		"user": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: "find by user (Mongo RegExp supported)",
		},
		"call": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: "find by api endpoint (Mongo RegExp supported)",
		},
		"min_status_code": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "find by HTTP min status code",
		},
		"max_status_code": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "find by HTTP max status code",
		},
		"sort_by": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: "sort by one of supported fields, format +|-(field)",
		},
		"page": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "page number",
		},
		"request_id": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: "request id",
		},
		"size": {
			Type:        schema.TypeInt,
			Optional:    true,
			Description: "page size",
		},
		"resgroup_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"compute_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"account_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"vins_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"service_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"k8s_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"flipgroup_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"lb_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"sep_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"node_id": {
			Type:     schema.TypeInt,
			Optional: true,
		},
		"exclude_audit_lines": {
			Type:     schema.TypeBool,
			Optional: true,
		},
		"items": {
			Type:     schema.TypeList,
			Computed: true,
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"call": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"correlation_id": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"guid": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"responsetime": {
						Type:     schema.TypeFloat,
						Computed: true,
					},
					"status_code": {
						Type:     schema.TypeInt,
						Computed: true,
					},
					"timestamp": {
						Type:     schema.TypeFloat,
						Computed: true,
					},
					"user": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"ttl": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"args": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"kwargs": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"result": {
						Type:     schema.TypeString,
						Computed: true,
					},
					"timestamp_end": {
						Type:     schema.TypeFloat,
						Computed: true,
					},
					"remote_addr": {
						Type:     schema.TypeString,
						Computed: true,
					},
				},
			},
		},
		"entry_count": {
			Type:        schema.TypeInt,
			Computed:    true,
			Description: "entry count",
		},
	}
}

func dataSourceLinkedJobsSchemaMake() map[string]*schema.Schema {
	return map[string]*schema.Schema{
		"audit_guid": {
			Type:        schema.TypeString,
			Required:    true,
			Description: "audit guid",
		},

		"items": {
			Type:     schema.TypeList,
			Computed: true,
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"cmd": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "cmd",
					},
					"guid": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "guid",
					},
					"nid": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "nid",
					},
					"physical_node": {
						Type:     schema.TypeBool,
						Computed: true,
					},
					"state": {
						Type:        schema.TypeString,
						Computed:    true,
						Description: "state",
					},
					"time_create": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "time create",
					},
					"time_start": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "time start",
					},
					"time_stop": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "time stop",
					},
					"timeout": {
						Type:        schema.TypeInt,
						Computed:    true,
						Description: "timeout",
					},
				},
			},
		},
	}
}

func dataSourceAuditToFileSchemaMake() map[string]*schema.Schema {
	return map[string]*schema.Schema{
		"file_path": {
			Type:        schema.TypeString,
			Optional:    true,
			Description: "file path",
		},
	}
}
