package v1alpha1

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

type O11yRoutePhase string

const (
	O11yRoutePhasePending   O11yRoutePhase = "Pending"
	O11yRoutePhaseCreating  O11yRoutePhase = "Creating"
	O11yRoutePhaseFailed    O11yRoutePhase = "Failed"
	O11yRoutePhaseActive    O11yRoutePhase = "Active"
	O11yRoutePhaseSuspended O11yRoutePhase = "Suspended"
	O11yRoutePhaseDeleting  O11yRoutePhase = "Deleting"
)

// +kubebuilder:object:root=true
// +kubebuilder:resource:categories=regionserver
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="PHASE",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// VPC is the Schema for the O11yRoute API
type O11yRoute struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   O11yRouteSpec   `json:"spec,omitempty"`
	Status O11yRouteStatus `json:"status,omitempty"`
}

type O11yRouteSpec struct {
	ApplicationID string `json:"applicationID"`

	// Suspend indicates related o11y cluster is paused
	//+optional
	Suspend bool `json:"suspend,omitempty"`

	// +optional
	Agent *AgentSpec `json:"agent,omitempty"`

	VPCRef Reference `json:"vpcRef"`

	APPBoxRef Reference `json:"appboxRef"`
	// +optional
	APPRouteRef *Reference `json:"appRouteRef,omitempty"`
}

type AgentSpec struct {
	TargetClusterVersion  string           `json:"targetClusterVersion"`
	TargetClusterTopology *ClusterTopology `json:"targetClusterTopology,omitempty"`
}

type ClusterTopology struct {
	TiDB    TiDB     `json:"tidb"`
	PD      PD       `json:"pd"`
	TiKV    TiKV     `json:"tikv"`
	TiFlash *TiFlash `json:"tiflash,omitempty"`
}

type TiDB struct {
	Replicas int `json:"replicas"`
}

type PD struct {
	Replicas int `json:"replicas"`
}

type TiKV struct {
	Replicas int `json:"replicas"`
}

type TiFlash struct {
	Replicas int `json:"replicas"`
}

type O11yRouteStatus struct {
	Phase O11yRoutePhase `json:"phase,omitempty"`
	// +optional
	Reason string `json:"reason,omitempty"`
	// +optional
	O11yID *string `json:"o11yID,omitempty"`
}

// +kubebuilder:object:root=true
type O11yRouteList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []O11yRoute `json:"items"`
}

func init() {
	SchemeBuilder.Register(&O11yRoute{}, &O11yRouteList{})
}
