/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
	"github.com/spf13/cobra"
	"github.com/tidbcloud/auto-deploy/internal"
)

var destroyAzureRegionArgs = internal.DestroyAzureRegionK8sArgs{}

// destroyAzureRegionCmd represents the destroy-azure-region-k8s command
var destroyAzureRegionCmd = &cobra.Command{
	Use:   "destroy-azure-region",
	Short: "Destroy Azure region after deploy",
	Long: `Destroy Azure region after deploy

For example:
deploy-cli destroy-azure-region-k8s                                                                  \
  --region-name eastus-eric                                                                          \
  --cloud-region eastus                                                                              \
  --meta-uri https://devautodeploymeta.blob.core.windows.net/meta/dedicated-regions/eastus/meta.yaml \
  --tenant-id 6c865c34-8ff8-4792-bbca-8c9d15efb29d                                                   \
  --subscription-id 85b598b9-a080-4476-bc96-ba89e64f92d1                                             \
  --client-id 6c865c34-8ff8-4792-bbca-8c9d15efb29d                                                   \
`,
	RunE: func(cmd *cobra.Command, _ []string) error {
		destroyAzureRegionArgs.InstanceName = instance
		destroyAzureRegionArgs.OidcProviderType = oidcProvider
		return internal.DestroyAzureRegionK8s(destroyAzureRegionArgs)
	},
}

func init() {
	rootCmd.AddCommand(destroyAzureRegionCmd)
	destroyAzureRegionCmd.Flags().StringVarP(&destroyAzureRegionArgs.RegionName, "region-name", "n", "", "Deployed region name")
	destroyAzureRegionCmd.Flags().StringVarP(&destroyAzureRegionArgs.MetaURI, "meta-uri", "", "", "Where to store or read metadata of this region")
	destroyAzureRegionCmd.Flags().StringVar(&destroyAzureRegionArgs.TenantId, "tenant-id", "", "Tenant id to destory k8s")
	destroyAzureRegionCmd.Flags().StringVar(&destroyAzureRegionArgs.SubscriptionId, "subscription-id", "", "Subscription id to destory k8s")
	destroyAzureRegionCmd.Flags().StringVar(&destroyAzureRegionArgs.ClientId, "client-id", "", "Client id to destory k8s")
	destroyAzureRegionCmd.Flags().StringVarP(&destroyAzureRegionArgs.Region, "cloud-region", "r", "", "Azure location to destroy k8s, for example: eastus")

	// mark required flag
	for _, flag := range []string{"region-name", "meta-uri", "role-arn", "cloud-region", "tenant-id", "subscription-id", "client-id"} {
		destroyAzureRegionCmd.MarkFlagRequired(flag)
	}
}
