package v1alpha1

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

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ContainerMomDeployment struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   ContainerMomDeploymentSpec   `json:"spec"`
	Status ContainerMomDeploymentStatus `json:"status"`
}

type ContainerMomDeploymentSpec struct {
	// Source configuration
	Source SourceSpec `json:"source"`

	// Target clusters for deployment
	Clusters []string `json:"clusters"`

	// Domain configuration
	Domain DomainSpec `json:"domain,omitempty"`

	// Resource requirements
	Resources ResourceRequirements `json:"resources"`

	// Environment variables
	Env []EnvVar `json:"env,omitempty"`

	// Billing tier
	BillingTier string `json:"billingTier"`
}

type SourceSpec struct {
	// Git repository URL
	GitURL string `json:"gitUrl,omitempty"`

	// Source to Image configuration
	BuildConfig *BuildConfig `json:"buildConfig,omitempty"`

	// Or direct container image
	Image string `json:"image,omitempty"`
}

type BuildConfig struct {
	BuilderImage string            `json:"builderImage"`
	BuildArgs    map[string]string `json:"buildArgs,omitempty"`
}

type DomainSpec struct {
	// Custom domain or use *.container.mom
	CustomDomain string `json:"customDomain,omitempty"`
	UseWildcard  bool   `json:"useWildcard,omitempty"`
	// TLS configuration
	TLS *TLSConfig `json:"tls,omitempty"`
	// DNS provider configuration for automatic DNS management
	DNSProvider *DNSProviderConfig `json:"dnsProvider,omitempty"`
}

type TLSConfig struct {
	// Use Let's Encrypt
	AutoCert bool `json:"autoCert,omitempty"`
	// Or use existing secret
	SecretName string `json:"secretName,omitempty"`
	// Email for Let's Encrypt notifications
	Email string `json:"email,omitempty"`
}

type DNSProviderConfig struct {
	// DNS provider (e.g., cloudflare, route53)
	Provider string `json:"provider"`
	// Credentials secret name
	SecretName string `json:"secretName"`
}

type ResourceRequirements struct {
	CPU    string `json:"cpu"`
	Memory string `json:"memory"`
	// Additional resource constraints
}

type EnvVar struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type ContainerMomDeploymentStatus struct {
	Phase          string          `json:"phase"`
	Conditions     []Condition     `json:"conditions,omitempty"`
	ClusterStatus  []ClusterStatus `json:"clusterStatus,omitempty"`
	LastUpdateTime metav1.Time     `json:"lastUpdateTime,omitempty"`
}

type Condition struct {
	Type    string `json:"type"`
	Status  string `json:"status"`
	Reason  string `json:"reason,omitempty"`
	Message string `json:"message,omitempty"`
}

type ClusterStatus struct {
	Name           string `json:"name"`
	Phase          string `json:"phase"`
	URL            string `json:"url,omitempty"`
	ReadyReplicas  int32  `json:"readyReplicas"`
	CurrentVersion string `json:"currentVersion,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ContainerMomDeploymentList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`

	Items []ContainerMomDeployment `json:"items"`
}
