package domain

// RuntimeConfig defines the configuration for each runtime
type RuntimeConfig struct {
	Name        string            `json:"name"`
	DisplayName string            `json:"display_name"`
	Image       string            `json:"image"`
	Handler     string            `json:"default_handler"`
	Extensions  []string          `json:"file_extensions"`
	Environment map[string]string `json:"default_environment"`
}

// GetRuntimeConfigs returns the available runtime configurations
func GetRuntimeConfigs() map[RuntimeType]RuntimeConfig {
	return map[RuntimeType]RuntimeConfig{
		"nodejs18": {
			Name:        "nodejs18",
			DisplayName: "Node.js 18.x",
			Image:       "node:18-alpine",
			Handler:     "index.handler",
			Extensions:  []string{".js", ".mjs", ".ts"},
			Environment: map[string]string{
				"NODE_ENV": "production",
			},
		},
		"python3.9": {
			Name:        "python3.9",
			DisplayName: "Python 3.9",
			Image:       "python:3.9-alpine",
			Handler:     "main.handler",
			Extensions:  []string{".py"},
			Environment: map[string]string{
				"PYTHONPATH": "/app",
			},
		},
		"go1.20": {
			Name:        "go1.20",
			DisplayName: "Go 1.20",
			Image:       "golang:1.20-alpine",
			Handler:     "main.Handler",
			Extensions:  []string{".go"},
			Environment: map[string]string{
				"CGO_ENABLED": "0",
				"GOOS":        "linux",
			},
		},
	}
}

// GetRuntimeConfig returns the configuration for a specific runtime
func GetRuntimeConfig(runtime RuntimeType) (RuntimeConfig, bool) {
	configs := GetRuntimeConfigs()
	config, exists := configs[runtime]
	return config, exists
}

// GetAvailableRuntimes returns a list of available runtimes for the frontend
func GetAvailableRuntimes() []map[string]string {
	configs := GetRuntimeConfigs()
	var runtimes []map[string]string
	
	for _, config := range configs {
		runtimes = append(runtimes, map[string]string{
			"value": config.Name,
			"label": config.DisplayName,
		})
	}
	
	return runtimes
}