package v1alpha1

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

// GenericPoolReq defines a request for a set of nodes with specific sizing.
// This is provider-agnostic.
type GenericPoolReq struct {
	// Name is the identifier for this node pool (e.g. "workers-gpu").
	// +required
	Name string `json:"name"`

	// Quantity is the number of nodes desired.
	// +required
	// +kubebuilder:validation:Minimum=0
	Quantity int `json:"quantity"`

	// CpuCores is the number of vCPUs per node.
	// +required
	// +kubebuilder:validation:Minimum=1
	CpuCores int `json:"cpuCores"`

	// MemoryGB is the amount of RAM per node in Gigabytes.
	// +required
	// +kubebuilder:validation:Minimum=1
	MemoryGB int `json:"memoryGb"`

	// DiskGB is the root disk size per node in Gigabytes.
	// +required
	// +kubebuilder:validation:Minimum=10
	DiskGB int `json:"diskGb"`
}

// ClusterBlueprintSpec defines the desired state of ClusterBlueprint
type ClusterBlueprintSpec struct {
	// InfraBlueprintRef points to the InfraBlueprint (IBP) that manages
	// the quotas and provider details for this cluster.
	// +required
	InfraBlueprintRef string `json:"infraBlueprintRef"`

	// KubernetesVersion is the target RKE2/K3s version (e.g., v1.28.0+rke2r1).
	// +required
	KubernetesVersion string `json:"kubernetesVersion"`

	// ControlPlaneHA determines if we provision 3 CP nodes (true) or 1 (false).
	// +optional
	ControlPlaneHA bool `json:"controlPlaneHA"`

	// WorkerPools is the list of worker node groups to provision.
	// +optional
	WorkerPools []GenericPoolReq `json:"workerPools,omitempty"`
}

// IdentityStatus tracks the generated cloud provider identity
type IdentityStatus struct {
	// SecretRef is the name of the generated secret used by this cluster.
	SecretRef string `json:"secretRef,omitempty"`

	// ServiceAccount is the name of the SA created on the provider (if applicable).
	ServiceAccount string `json:"serviceAccount,omitempty"`
}

// ClusterBlueprintStatus defines the observed state of ClusterBlueprint
type ClusterBlueprintStatus struct {
	// Ready indicates if the Helm Chart has been successfully applied.
	Ready bool `json:"ready"`

	// Identity tracks the cloud credentials generated for this cluster.
	// +optional
	Identity *IdentityStatus `json:"identity,omitempty"`

	// Phase can be "Pending", "Provisioning", "Deployed", or "Failed"
	// +optional
	Phase string `json:"phase,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=cbp
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="K8s Version",type="string",JSONPath=".spec.kubernetesVersion"
// +kubebuilder:printcolumn:name="Infra",type="string",JSONPath=".spec.infraBlueprintRef"
type ClusterBlueprint struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   ClusterBlueprintSpec   `json:"spec,omitempty"`
	Status ClusterBlueprintStatus `json:"status,omitempty"`
}

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

func init() {
	SchemeBuilder.Register(&ClusterBlueprint{}, &ClusterBlueprintList{})
}
