// copyed from https://github.com/pingcap/tidb-operator/blob/master/pkg/apis/pingcap/v1alpha1/types.go
package resource

// MemberPhase is the current state of member
type MemberPhase string

// DMClusterConditionType represents a dm cluster condition value.
type DMClusterConditionType string

const (
	// DMClusterReady indicates that the dm cluster is ready or not.
	// This is defined as:
	// - All statefulsets are up to date (currentRevision == updateRevision).
	// - All Master members are healthy.
	// - All Worker pods are up.
	DMClusterReady DMClusterConditionType = "Ready"
)

// DMCluster is the control script's spec
type DMCluster struct {
	ResourceHandle `json:",inline"`

	// Spec defines the behavior of a dm cluster
	Spec DMClusterSpec `json:"spec"`

	// Most recently observed status of the dm cluster
	Status DMClusterStatus `json:"status"`
}

type DMClusterSpec struct {

	// dm-master cluster spec
	Master MasterSpec `json:"master"`

	// dm-worker cluster spec
	Worker *WorkerSpec `json:"worker,omitempty"`

	// dm cluster version
	Version string `json:"version"`

	// Additional labels for the dm cluster
	// Can be overrode by labels in master spec or worker spec
	Labels map[string]string `json:"labels,omitempty"`
}

// DMClusterStatus represents the current status of a dm cluster.
type DMClusterStatus struct {
	Master MasterStatus `json:"master,omitempty"`
	Worker WorkerStatus `json:"worker,omitempty"`

	// Represents the latest available observations of a dm cluster's state.
	Conditions []DMClusterCondition `json:"conditions,omitempty"`
}

type MasterSpec struct {

	// The desired ready replicas
	Replicas int32 `json:"replicas"`

	Version string `json:"version"`
	// Base image of the component, image tag is now allowed during validation
	BaseImage string `json:"baseImage,omitempty"`
}

// WorkerSpec contains details of dm-worker members
type WorkerSpec struct {
	// The desired ready replicas
	Replicas int32 `json:"replicas"`

	Version string `json:"version"`
	// Base image of the component, image tag is now allowed during validation
	BaseImage string `json:"baseImage,omitempty"`
}

// MasterStatus is dm-master status
type MasterStatus struct {
	Synced bool        `json:"synced,omitempty"`
	Phase  MemberPhase `json:"phase,omitempty"`
	Image  string      `json:"image,omitempty"`
}

type WorkerStatus struct {
	Synced bool        `json:"synced,omitempty"`
	Phase  MemberPhase `json:"phase,omitempty"`
	Image  string      `json:"image,omitempty"`
}

// DMClusterCondition is dm cluster condition
type DMClusterCondition struct {
	// Type of the condition.
	Type DMClusterConditionType `json:"type"`
	// Status of the condition, one of True, False, Unknown.

	// The reason for the condition's last transition.
	// +optional
	Reason string `json:"reason,omitempty"`
	// A human readable message indicating details about the transition.
	// +optional
	Message string `json:"message,omitempty"`
}
