package cloud_provider

import (
	"github.com/juju/errors"
	"github.com/tidbcloud/auto-deploy/internal/types"
	"gopkg.in/yaml.v3"
)

func getCreateK8sArgs(k8s *types.K8s) (string, error) {
	args := make(map[string]any)
	args["k8s"] = k8s
	region := map[string]any{
		"name":   k8s.Region.Name,
		"region": k8s.Region.Region,
		"env":    k8s.Region.InstanceName,
	}

	switch k8s.Region.CloudProviderType {
	case types.AWS:
		region["accountId"] = k8s.Region.Account.AwsRole.AccountId
	case types.Azure:
		region["imageRegistry"] = k8s.Region.ImageRegistry
	}
	args["region"] = region

	argsStr, err := yaml.Marshal(args)
	if err != nil {
		return "", errors.BadRequestf("k8s arg")
	}
	return string(argsStr), nil
}
