// SPDX-License-Identifier: GPL-3.0-or-later

package coredns

import "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi"

type (
	// Charts is an alias for collectorapi.Charts
	Charts = collectorapi.Charts
	// Chart is an alias for collectorapi.Chart
	Chart = collectorapi.Chart
	// Dims is an alias for collectorapi.Dims
	Dims = collectorapi.Dims
	// Dim is an alias for collectorapi.Dim
	Dim = collectorapi.Dim
)

var summaryCharts = Charts{
	{
		ID:    "dns_request_count_total",
		Title: "Number Of DNS Requests",
		Units: "requests/s",
		Fam:   "summary",
		Ctx:   "coredns.dns_request_count_total",
		Dims: Dims{
			{ID: "request_total", Name: "requests", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "dns_responses_count_total",
		Title: "Number Of DNS Responses",
		Units: "responses/s",
		Fam:   "summary",
		Ctx:   "coredns.dns_responses_count_total",
		Dims: Dims{
			{ID: "response_total", Name: "responses", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "dns_request_count_total_per_status",
		Title: "Number Of Processed And Dropped DNS Requests",
		Units: "requests/s",
		Fam:   "summary",
		Ctx:   "coredns.dns_request_count_total_per_status",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "request_per_status_processed", Name: "processed", Algo: collectorapi.Incremental},
			{ID: "request_per_status_dropped", Name: "dropped", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "dns_no_matching_zone_dropped_total",
		Title: "Number Of Dropped DNS Requests Because Of No Matching Zone",
		Units: "requests/s",
		Fam:   "summary",
		Ctx:   "coredns.dns_no_matching_zone_dropped_total",
		Dims: Dims{
			{ID: "no_matching_zone_dropped_total", Name: "dropped", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "dns_panic_count_total",
		Title: "Number Of Panics",
		Units: "panics/s",
		Fam:   "summary",
		Ctx:   "coredns.dns_panic_count_total",
		Dims: Dims{
			{ID: "panic_total", Name: "panics", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "dns_requests_count_total_per_proto",
		Title: "Number Of DNS Requests Per Transport Protocol",
		Units: "requests/s",
		Fam:   "summary",
		Ctx:   "coredns.dns_requests_count_total_per_proto",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "request_per_proto_udp", Name: "udp", Algo: collectorapi.Incremental},
			{ID: "request_per_proto_tcp", Name: "tcp", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "dns_requests_count_total_per_ip_family",
		Title: "Number Of DNS Requests Per IP Family",
		Units: "requests/s",
		Fam:   "summary",
		Ctx:   "coredns.dns_requests_count_total_per_ip_family",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "request_per_ip_family_v4", Name: "v4", Algo: collectorapi.Incremental},
			{ID: "request_per_ip_family_v6", Name: "v6", Algo: collectorapi.Incremental},
		},
	},
	//{
	//	ID:    "dns_requests_duration_seconds",
	//	Title: "Number Of DNS Requests Per Bucket",
	//	Units: "requests/s",
	//	Fam:   "summary",
	//	Ctx:   "coredns.dns_requests_duration_seconds",
	//	Type:  module.Stacked,
	//	Dims: Dims{
	//		{ID: "request_duration_seconds_bucket_0.00025", Name: "0.00025s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.0005", Name: "0.0005s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.001", Name: "0.001s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.002", Name: "0.002s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.004", Name: "0.004s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.008", Name: "0.008s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.016", Name: "0.016s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.032", Name: "0.032s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.064", Name: "0.064s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.128", Name: "0.128s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.256", Name: "0.256s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_0.512", Name: "0.512s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_1.024", Name: "1.024s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_2.048", Name: "2.048s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_4.096", Name: "4.096s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_8.192", Name: "8.192s", Algo: module.Incremental},
	//		{ID: "request_duration_seconds_bucket_+Inf", Name: "+Inf", Algo: module.Incremental},
	//	},
	//},
	{
		ID:    "dns_requests_count_total_per_type",
		Title: "Number Of DNS Requests Per Type",
		Units: "requests/s",
		Fam:   "summary",
		Ctx:   "coredns.dns_requests_count_total_per_per_type",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "request_per_type_A", Name: "A", Algo: collectorapi.Incremental},
			{ID: "request_per_type_AAAA", Name: "AAAA", Algo: collectorapi.Incremental},
			{ID: "request_per_type_MX", Name: "MX", Algo: collectorapi.Incremental},
			{ID: "request_per_type_SOA", Name: "SOA", Algo: collectorapi.Incremental},
			{ID: "request_per_type_CNAME", Name: "CNAME", Algo: collectorapi.Incremental},
			{ID: "request_per_type_PTR", Name: "PTR", Algo: collectorapi.Incremental},
			{ID: "request_per_type_TXT", Name: "TXT", Algo: collectorapi.Incremental},
			{ID: "request_per_type_NS", Name: "NS", Algo: collectorapi.Incremental},
			{ID: "request_per_type_DS", Name: "DS", Algo: collectorapi.Incremental},
			{ID: "request_per_type_DNSKEY", Name: "DNSKEY", Algo: collectorapi.Incremental},
			{ID: "request_per_type_RRSIG", Name: "RRSIG", Algo: collectorapi.Incremental},
			{ID: "request_per_type_NSEC", Name: "NSEC", Algo: collectorapi.Incremental},
			{ID: "request_per_type_NSEC3", Name: "NSEC3", Algo: collectorapi.Incremental},
			{ID: "request_per_type_IXFR", Name: "IXFR", Algo: collectorapi.Incremental},
			{ID: "request_per_type_ANY", Name: "ANY", Algo: collectorapi.Incremental},
			{ID: "request_per_type_other", Name: "other", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "dns_responses_count_total_per_rcode",
		Title: "Number Of DNS Responses Per Rcode",
		Units: "responses/s",
		Fam:   "summary",
		Ctx:   "coredns.dns_responses_count_total_per_rcode",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "response_per_rcode_NOERROR", Name: "NOERROR", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_FORMERR", Name: "FORMERR", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_SERVFAIL", Name: "SERVFAIL", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_NXDOMAIN", Name: "NXDOMAIN", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_NOTIMP", Name: "NOTIMP", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_REFUSED", Name: "REFUSED", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_YXDOMAIN", Name: "YXDOMAIN", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_YXRRSET", Name: "YXRRSET", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_NXRRSET", Name: "NXRRSET", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_NOTAUTH", Name: "NOTAUTH", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_NOTZONE", Name: "NOTZONE", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_BADSIG", Name: "BADSIG", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_BADKEY", Name: "BADKEY", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_BADTIME", Name: "BADTIME", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_BADMODE", Name: "BADMODE", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_BADNAME", Name: "BADNAME", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_BADALG", Name: "BADALG", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_BADTRUNC", Name: "BADTRUNC", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_BADCOOKIE", Name: "BADCOOKIE", Algo: collectorapi.Incremental},
			{ID: "response_per_rcode_other", Name: "other", Algo: collectorapi.Incremental},
		},
	},
}

var serverCharts = Charts{
	{
		ID:    "per_%s_%s_dns_request_count_total",
		Title: "Number Of DNS Requests, %s %s",
		Units: "requests/s",
		Fam:   "%s %s",
		Ctx:   "coredns.server_dns_request_count_total",
		Dims: Dims{
			{ID: "%s_request_total", Name: "requests", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "per_%s_%s_dns_responses_count_total",
		Title: "Number Of DNS Responses, %s %s",
		Units: "responses/s",
		Fam:   "%s %s",
		Ctx:   "coredns.server_dns_responses_count_total",
		Dims: Dims{
			{ID: "%s_response_total", Name: "responses", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "per_%s_%s_dns_request_count_total_per_status",
		Title: "Number Of Processed And Dropped DNS Requests, %s %s",
		Units: "requests/s",
		Fam:   "%s %s",
		Ctx:   "coredns.server_dns_request_count_total_per_status",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "%s_request_per_status_processed", Name: "processed", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_status_dropped", Name: "dropped", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "per_%s_%s_dns_requests_count_total_per_proto",
		Title: "Number Of DNS Requests Per Transport Protocol, %s %s",
		Units: "requests/s",
		Fam:   "%s %s",
		Ctx:   "coredns.server_dns_requests_count_total_per_proto",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "%s_request_per_proto_udp", Name: "udp", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_proto_tcp", Name: "tcp", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "per_%s_%s_dns_requests_count_total_per_ip_family",
		Title: "Number Of DNS Requests Per IP Family, %s %s",
		Units: "requests/s",
		Fam:   "%s %s",
		Ctx:   "coredns.server_dns_requests_count_total_per_ip_family",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "%s_request_per_ip_family_v4", Name: "v4", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_ip_family_v6", Name: "v6", Algo: collectorapi.Incremental},
		},
	},
	//{
	//	ID:    "per_%s_%s_dns_requests_duration_seconds",
	//	Title: "Number Of DNS Requests Per Bucket, %s %s",
	//	Units: "requests/s",
	//	Fam:   "%s %s",
	//	Ctx:   "coredns.server_dns_requests_duration_seconds",
	//	Type:  module.Stacked,
	//	Dims: Dims{
	//		{ID: "%s_request_duration_seconds_bucket_0.00025", Name: "0.00025s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.0005", Name: "0.0005s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.001", Name: "0.001s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.002", Name: "0.002s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.004", Name: "0.004s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.008", Name: "0.008s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.016", Name: "0.016s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.032", Name: "0.032s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.064", Name: "0.064s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.128", Name: "0.128s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.256", Name: "0.256s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_0.512", Name: "0.512s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_1.024", Name: "1.024s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_2.048", Name: "2.048s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_4.096", Name: "4.096s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_8.192", Name: "8.192s", Algo: module.Incremental},
	//		{ID: "%s_request_duration_seconds_bucket_+Inf", Name: "+Inf", Algo: module.Incremental},
	//	},
	//},
	{
		ID:    "per_%s_%s_dns_requests_count_total_per_type",
		Title: "Number Of DNS Requests Per Type, %s %s",
		Units: "requests/s",
		Fam:   "%s %s",
		Ctx:   "coredns.server_dns_requests_count_total_per_per_type",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "%s_request_per_type_A", Name: "A", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_AAAA", Name: "AAAA", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_MX", Name: "MX", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_SOA", Name: "SOA", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_CNAME", Name: "CNAME", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_PTR", Name: "PTR", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_TXT", Name: "TXT", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_NS", Name: "NS", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_DS", Name: "DS", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_DNSKEY", Name: "DNSKEY", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_RRSIG", Name: "RRSIG", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_NSEC", Name: "NSEC", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_NSEC3", Name: "NSEC3", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_IXFR", Name: "IXFR", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_ANY", Name: "ANY", Algo: collectorapi.Incremental},
			{ID: "%s_request_per_type_other", Name: "other", Algo: collectorapi.Incremental},
		},
	},
	{
		ID:    "per_%s_%s_dns_responses_count_total_per_rcode",
		Title: "Number Of DNS Responses Per Rcode, %s %s",
		Units: "responses/s",
		Fam:   "%s %s",
		Ctx:   "coredns.server_dns_responses_count_total_per_rcode",
		Type:  collectorapi.Stacked,
		Dims: Dims{
			{ID: "%s_response_per_rcode_NOERROR", Name: "NOERROR", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_FORMERR", Name: "FORMERR", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_SERVFAIL", Name: "SERVFAIL", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_NXDOMAIN", Name: "NXDOMAIN", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_NOTIMP", Name: "NOTIMP", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_REFUSED", Name: "REFUSED", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_YXDOMAIN", Name: "YXDOMAIN", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_YXRRSET", Name: "YXRRSET", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_NXRRSET", Name: "NXRRSET", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_NOTAUTH", Name: "NOTAUTH", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_NOTZONE", Name: "NOTZONE", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_BADSIG", Name: "BADSIG", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_BADKEY", Name: "BADKEY", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_BADTIME", Name: "BADTIME", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_BADMODE", Name: "BADMODE", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_BADNAME", Name: "BADNAME", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_BADALG", Name: "BADALG", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_BADTRUNC", Name: "BADTRUNC", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_BADCOOKIE", Name: "BADCOOKIE", Algo: collectorapi.Incremental},
			{ID: "%s_response_per_rcode_other", Name: "other", Algo: collectorapi.Incremental},
		},
	},
}

var zoneCharts = func() Charts {
	c := serverCharts.Copy()
	_ = c.Remove("per_%s_%s_dns_request_count_total_per_status")
	return *c
}()
