package v1alpha1

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

// ResourceDiscoverySpec defines the desired state of ResourceDiscovery
type ResourceDiscoverySpec struct {
	// Provider is the provider to discover resources from
	// +kubebuilder:validation:Required
	// +kubebuilder:validation:Enum=PROXMOX;KUBERNETES;CLOUDFLARE;CEPH;MINIO
	Provider string `json:"provider"`

	// Site is the site identifier
	Site string `json:"site,omitempty"`

	// Region is the region identifier
	Region string `json:"region,omitempty"`

	// SyncInterval is the interval between discovery syncs (in seconds)
	// +kubebuilder:default=300
	SyncInterval int `json:"syncInterval,omitempty"`

	// Enabled indicates whether discovery is enabled
	// +kubebuilder:default=true
	Enabled bool `json:"enabled,omitempty"`

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

// ResourceDiscoveryStatus defines the observed state of ResourceDiscovery
type ResourceDiscoveryStatus struct {
	// LastSyncTime is the timestamp of the last successful sync
	LastSyncTime *metav1.Time `json:"lastSyncTime,omitempty"`

	// ResourcesDiscovered is the number of resources discovered in the last sync
	ResourcesDiscovered int `json:"resourcesDiscovered,omitempty"`

	// SyncStatus is the status of the last sync
	// +kubebuilder:validation:Enum=SUCCESS;FAILED;IN_PROGRESS
	SyncStatus string `json:"syncStatus,omitempty"`

	// LastSyncError is the error message from the last sync (if any)
	LastSyncError string `json:"lastSyncError,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="PROVIDER",type="string",JSONPath=".spec.provider"
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.syncStatus"
// +kubebuilder:printcolumn:name="RESOURCES",type="integer",JSONPath=".status.resourcesDiscovered"
// +kubebuilder:printcolumn:name="LAST_SYNC",type="date",JSONPath=".status.lastSyncTime"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"

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

	Spec   ResourceDiscoverySpec   `json:"spec,omitempty"`
	Status ResourceDiscoveryStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
	SchemeBuilder.Register(&ResourceDiscovery{}, &ResourceDiscoveryList{})
}

