package v1alpha1

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

// EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.

type SelectorOperator string

type StringMatch struct {
	Prefix string `json:"prefix,omitempty"`
	Exact  string `json:"exact,omitempty"`
}

type MatchExpression struct {
	ID     uint32 `json:"id,omitempty"`
	Name   string `json:"name,omitempty"`
	Mode   string `json:"mode,omitempty"`
	Scope  string `json:"scope,omitempty"`
	Expr   string `json:"expr,omitempty"`
	Status int32  `json:"status,omitempty"`
}

type LogConfig struct {
	Enable int    `json:"attack_enable,omitempty"`
	Level  string `json:"level,omitempty"`
}

type WorkloadRef struct {
	ClusterKey string `json:"clusterKey"`
	Namespace  string `json:"namespace"`
	Kind       string `json:"kind"`
	Name       string `json:"name"`
}

type Rule struct {
	ID          int    `json:"id"`
	Level       int    `json:"level"`
	Type        string `json:"type"`
	Description string `json:"description"`
	Expr        string `json:"expr"`
	Mode        string `json:"mode"`
	Name        string `json:"name"`
}

// ServiceSpec defines the desired state of Service
type ServiceSpec struct {
	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
	// Important: Run "make" to regenerate code after modifying this file
	HostNames         []string          `json:"hostNames,omitempty"`
	Uri               *StringMatch      `json:"uri,omitempty"`
	Mode              string            `json:"mode"`
	LogConfig         *LogConfig        `json:"logConfig,omitempty"`
	BlackWhireLists   []MatchExpression `json:"blackWhireLists,omitempty"`
	ExcludedFileTypes []string          `json:"excludedFileTypes,omitempty"`
	DetectHeaders     []string          `json:"detect_headers,omitempty"`
	Workload          WorkloadRef       `json:"workload"`
	Secret            string            `json:"secret,omitempty"`
	ServiceName       string            `json:"serviceName"`
	ServiceID         uint32            `json:"serviceId"`
	Rules             []Rule            `json:"rules,omitempty"`
	Port              uint32            `json:"port"`
}

type ServicePort struct {
	Port       int32              `json:"port"`
	TargetPort intstr.IntOrString `json:"targetPort"`
	HttpsPort  int32              `json:"httpsPort"`
}

// ServiceStatus defines the observed state of Service
type ServiceStatus struct {
	// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
	// Important: Run "make" to regenerate code after modifying this file
	SecretVervision    string                   `json:"secretRevision,omitempty"`
	ObservedGeneration int64                    `json:"observedGeneration,omitempty"`
	Labels             map[string]string        `json:"labels,omitempty"`
	KubeServices       map[string][]ServicePort `json:"kubeSerices,omitempty"`
	BwListVervision    string                   `json:"bwListVersion,omitempty"`
	CoreServiceVersion int64                    `json:"coreServiceVersion,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +genclient
// Service is the Schema for the services API
type Service struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              ServiceSpec   `json:"spec,omitempty"`
	Status            ServiceStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// ServiceList contains a list of Service
type ServiceList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Service `json:"items"`
}
