package v1alpha1

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

// GPURequirement defines GPU requirements
type GPURequirement struct {
	// Type of GPU (e.g., "nvidia-a100", "nvidia-v100")
	Type string `json:"type"`

	// Count is the number of GPUs
	// +kubebuilder:validation:Minimum=1
	Count int `json:"count"`

	// Memory is the GPU memory requirement (e.g., "40GB")
	Memory string `json:"memory,omitempty"`
}

// MLFrameworkRequirement defines ML framework requirements
type MLFrameworkRequirement struct {
	// Framework name (e.g., "pytorch", "tensorflow")
	Framework string `json:"framework"`

	// Version of the framework
	Version string `json:"version,omitempty"`

	// CUDA version if needed
	CUDAVersion string `json:"cudaVersion,omitempty"`
}

// GPUVMSpec defines the desired state of ProxmoxGPUVM
type GPUVMSpec struct {
	// Extend ProxmoxVMParameters
	ProxmoxVMParameters `json:",inline"`

	// GPU requirements
	GPU GPURequirement `json:"gpu"`

	// ML framework requirements
	MLFrameworks []MLFrameworkRequirement `json:"mlFrameworks,omitempty"`

	// GPU passthrough configuration
	GPUPassthrough bool `json:"gpuPassthrough,omitempty"`

	// ProviderConfigReference specifies how the provider should be configured
	// +kubebuilder:validation:Required
	ProviderConfigReference *ProviderConfigReference `json:"providerConfigRef"`
}

// GPUVMStatus defines the observed state of ProxmoxGPUVM
type GPUVMStatus struct {
	// VMID is the Proxmox VM ID
	VMID int `json:"vmId,omitempty"`

	// State is the current state of the VM
	State string `json:"state,omitempty"`

	// IPAddress is the IP address of the VM
	IPAddress string `json:"ipAddress,omitempty"`

	// GPUAllocated indicates if GPU is allocated
	GPUAllocated bool `json:"gpuAllocated,omitempty"`

	// GPUHealth is the health status of the GPU
	GPUHealth string `json:"gpuHealth,omitempty"`

	// Conditions represent the latest available observations of the resource's state
	Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="VMID",type="integer",JSONPath=".status.vmId"
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.state"
// +kubebuilder:printcolumn:name="GPU",type="string",JSONPath=".spec.gpu.type"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"

// ProxmoxGPUVM is the Schema for the proxmoxgpuvms API
type ProxmoxGPUVM struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   GPUVMSpec   `json:"spec,omitempty"`
	Status GPUVMStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
	SchemeBuilder.Register(&ProxmoxGPUVM{}, &ProxmoxGPUVMList{})
}

