package config

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type NamespacedName struct {
	Namespace string `json:"namespace"`
	Name      string `json:"name,omitempty"`
}

type ResourceMatchOption struct {
	// LabelSelector filters resources by their labels when listing.
	LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`

	// FieldSelector filters resources by their fields when listing.
	FieldSelector string `json:"fieldSelector,omitempty"`

	// Namespace represents the namespace to list for, or empty for
	// non-namespaced objects, or to list across all namespaces.
	Namespace string `json:"namespace,omitempty"`

	// FilterNamespacedNames is the list of namespaced name that will be filtered.
	// If name is empty, all resource in the namespace will be filtered.
	FilterNamespacedNames []NamespacedName `json:"filterNamespaces,omitempty"`
}

type ResourceMatch struct {
	ResourceMatchOption `json:",inline"`

	// APIVersion is the resource API version, e.g. v1, apps/v1, etc.
	APIVersion string `json:"apiVersion"`

	// Kind is the resource kind, e.g. Pod, Deployment, etc.
	// If Kind is empty, all kinds in the APIVersion will be matched.
	Kind string `json:"kind"`
}

type DataplaneMatch struct {
	// LabelSelector is the label selector to filter Networks when listing.
	//
	// If the label selector is empty, filter Networks by the label `tags.tidbcloud.com/servicetype: dedicated`.
	LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`

	// Namespace represents the namespace to list for, or empty for
	// non-namespaced objects, or to list across all namespaces.
	Namespace string `json:"namespace,omitempty"`

	// FilterNamespacedNames is the list of namespaced name that will be filtered.
	// If name is empty, all resource in the namespace will be filtered.
	FilterNamespacedNames []NamespacedName `json:"filterNamespaces,omitempty"`
}

// ListConfig is the configuration to make inspector know what resources to inspect.
type ListConfig struct {
	// Resources is the list of resources that will be inspected.
	Resources []ResourceMatch `json:"resources"`

	// DataplaneMatch filter some dataplanes, it is used to filter the Network CR.
	// It is ONLY used in the dataplane inspector.
	Dataplane *DataplaneMatch `json:"dataplane,omitempty"`
}
