package cmd

import (
	"github.com/carapace-sh/carapace"
	"github.com/carapace-sh/carapace-bin/completers/common/kubeadm_completer/cmd/action"
	"github.com/spf13/cobra"
)

var upgrade_applyCmd = &cobra.Command{
	Use:   "apply [version]",
	Short: "Upgrade your Kubernetes cluster to the specified version",
	Run:   func(cmd *cobra.Command, args []string) {},
}

func init() {
	carapace.Gen(upgrade_applyCmd).Standalone()

	upgrade_applyCmd.Flags().Bool("allow-experimental-upgrades", false, "Show unstable versions of Kubernetes as an upgrade alternative and allow upgrading to an alpha/beta/release candidate versions of Kubernetes.")
	upgrade_applyCmd.Flags().Bool("allow-release-candidate-upgrades", false, "Show release candidate versions of Kubernetes as an upgrade alternative and allow upgrading to a release candidate versions of Kubernetes.")
	upgrade_applyCmd.Flags().Bool("certificate-renewal", false, "Perform the renewal of certificates used by component changed during upgrades.")
	upgrade_applyCmd.Flags().String("config", "", "Path to a kubeadm configuration file.")
	upgrade_applyCmd.Flags().Bool("dry-run", false, "Do not change any state, just output what actions would be performed.")
	upgrade_applyCmd.Flags().Bool("etcd-upgrade", false, "Perform the upgrade of etcd.")
	upgrade_applyCmd.Flags().BoolP("force", "f", false, "Force upgrading although some requirements might not be met. This also implies non-interactive mode.")
	upgrade_applyCmd.Flags().StringSlice("ignore-preflight-errors", nil, "A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.")
	upgrade_applyCmd.Flags().String("kubeconfig", "", "The kubeconfig file to use when talking to the cluster. If the flag is not set, a set of standard locations can be searched for an existing kubeconfig file.")
	upgrade_applyCmd.Flags().String("patches", "", "Path to a directory that contains files named \"target[suffix][+patchtype].extension\". For example, \"kube-apiserver0+merge.yaml\" or just \"etcd.json\". \"target\" can be one of \"kube-apiserver\", \"kube-controller-manager\", \"kube-scheduler\", \"etcd\", \"kubeletconfiguration\", \"corednsdeployment\". \"patchtype\" can be one of \"strategic\", \"merge\" or \"json\" and they match the patch formats supported by kubectl. The default \"patchtype\" is \"strategic\". \"extension\" must be either \"json\" or \"yaml\". \"suffix\" is an optional string that can be used to determine which patches are applied first alpha-numerically.")
	upgrade_applyCmd.Flags().Bool("print-config", false, "Specifies whether the configuration file that will be used in the upgrade should be printed or not.")
	upgrade_applyCmd.Flags().StringSlice("skip-phases", nil, "List of phases to be skipped")
	upgrade_applyCmd.Flags().BoolP("yes", "y", false, "Perform the upgrade and do not prompt for confirmation (non-interactive mode).")
	upgradeCmd.AddCommand(upgrade_applyCmd)

	carapace.Gen(upgrade_applyCmd).FlagCompletion(carapace.ActionMap{
		"config":                  carapace.ActionFiles(),
		"ignore-preflight-errors": action.ActionChecks().UniqueList(","),
		"kubeconfig":              carapace.ActionFiles(),
		"patches":                 carapace.ActionDirectories(),
	})
}
