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

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

var updateRegionInfoArgs = internal.UpdateRegionInfoArgs{}

// updateRegionInfoCmd represents the update-region-info command
var updateRegionInfoCmd = &cobra.Command{
	Use:   "update-region-info",
	Short: "Update Region Info",
	Long: `Update region, including state, is-public, open tenants, if not set keep the old value
For example:
deploy-cli update-region-state \
  --instance dev
  --cloud aws
  --logical-name ap-northeast-1-test2
  --state inactive
  --is-public false
  --opened-tenant-ids 65502
`,
	RunE: func(cmd *cobra.Command, _ []string) error {
		updateRegionInfoArgs.Env = instance
		return internal.UpdateRegion(updateRegionInfoArgs)
	},
}

func init() {
	rootCmd.AddCommand(updateRegionInfoCmd)
	updateRegionInfoCmd.Flags().StringVar(&updateRegionInfoArgs.CloudProvider, "cloud", "", "Cloud Provider: aws, gcp or azure")
	updateRegionInfoCmd.Flags().StringVar(&updateRegionInfoArgs.LogicalName, "logical-name", "", "Cloud region (location), for example: us-west-2, eu-central-1")
	updateRegionInfoCmd.Flags().StringVar(&updateRegionInfoArgs.State, "state", "", "Cloud region state, active or inactive")
	updateRegionInfoCmd.Flags().StringSliceVar(&updateRegionInfoArgs.OpenedTenantIds, "opened-tenant-ids", []string{}, "Opened tenant id list")
	updateRegionInfoCmd.Flags().StringVar(&updateRegionInfoArgs.IsPublic, "is-public", "", "Region is public for all tenants")
	updateRegionInfoCmd.Flags().StringVarP(&updateRegionInfoArgs.DeployType, "deploy-type", "", "DEPLOY_TYPE_DEDICATED", "Which type of region to deploy, default is dedicated, can be DEPLOY_TYPE_DEDICATED, DEPLOY_TYPE_NEXTGEN")

	// mark required flag
	for _, flag := range []string{"cloud", "region", "deploy-type"} {
		updateRegionInfoCmd.MarkFlagRequired(flag)
	}
}
