// Package gke add by blacknc <blacknc@163.com> at 2025/03/12 11:55:48
package gke

import (
	"fmt"

	"github.com/tidbcloud/eks-provider/controllers/imports/task"
	"github.com/tidbcloud/infra-provider/pkg/namer"
	infrautil "github.com/tidbcloud/infra-provider/pkg/util"
)

const (
	nodePoolNamePrefix = "import"
)

func getGCPNodePoolServiceAccountEmail(t *task.BaseTask) (string, error) {
	if t.ClusterRole == nil {
		return "", fmt.Errorf("cluster role is nil: may be not initialized or does not exist")
	}
	return t.ClusterRole.CloudIamIdentity, nil
}

func getNodePoolName(t *task.BaseTask) string {
	originalString := fmt.Sprintf("%s/%s/%s/%s",
		t.GetClusterScopeName(),
		t.Import.Name,
		task.LightningComponent,
		t.Config.ImportConfig.InstanceType)
	prefix := nodePoolNamePrefix + "-" + infrautil.FnvHash(originalString)
	return namer.UniqueIdentifier(t.Import.ObjectMeta, namer.WithPrefix(prefix), namer.WithLimit(namer.GKENameLimit))
}
