package sync

import (
	"fmt"
	"strings"

	syncpkg "github.com/argoproj/argo-workflows/v4/pkg/apiclient/sync"
)

func validateFlags(syncType, cmName string) error {
	if _, ok := syncpkg.SyncConfigType_value[syncType]; !ok {
		return fmt.Errorf("--type must be either 'database' or 'configmap'")
	}

	if syncType == syncpkg.SyncConfigType_CONFIGMAP.String() && cmName == "" {
		return fmt.Errorf("--cm-name is required when type is configmap")
	}

	return nil
}

func printSyncLimit(key, cmName, namespace string, limit int32, syncType syncpkg.SyncConfigType) {
	fmt.Printf("Key: %s\n", key)
	fmt.Printf("Type: %s\n", strings.ToLower(syncType.String()))
	if syncType == syncpkg.SyncConfigType_CONFIGMAP {
		fmt.Printf("ConfigMap Name: %s\n", cmName)
	}
	fmt.Printf("Namespace: %s\n", namespace)
	fmt.Printf("Limit: %d\n", limit)
}
