package framework

import (
	"os"

	"github.com/spf13/pflag"
	"github.com/tidbcloud/shared-provider/tests/framework/env/config"
)

const (
	CloudEKS = "eks"
	CloudGKE = "gke"
)

type TestConfig struct {
	Environment config.Config

	NamespaceBaseName string

	InfraAPICRDPaths []string

	KubeClusterNameBase string

	AWSRegion string
	GCPRegion string

	AWSCallerIdentity string

	Selector string

	Cloud string
}

func (c *TestConfig) RegisterFlags(fs *pflag.FlagSet) {
	fs.StringVar(&c.Environment.User.Kubeconfig,
		"kubeconfig",
		c.Environment.User.Kubeconfig,
		"config of user kubernetes cluster")
	fs.StringVar(&c.Environment.User.Context,
		"context",
		c.Environment.User.Context,
		"context of user kubernetes cluster")
	fs.StringVar(&c.Environment.InfraAPI.Kubeconfig,
		"infra-kubeconfig",
		c.Environment.InfraAPI.Kubeconfig,
		"config of infra kubernetes cluster")
	fs.StringVar(&c.Environment.InfraAPI.Context,
		"infra-context",
		c.Environment.InfraAPI.Context,
		"context of infra kubernetes cluster")

	fs.StringVar(&c.NamespaceBaseName,
		"namespace-base-name",
		c.NamespaceBaseName,
		"base name of created namespace",
	)

	fs.StringSliceVar(&c.InfraAPICRDPaths,
		"infra-api-crd-paths",
		c.InfraAPICRDPaths,
		"crd paths of infra api",
	)
	fs.StringVar(&c.KubeClusterNameBase,
		"kube-cluster-name-base",
		c.KubeClusterNameBase,
		"base of kube cluster name",
	)

	fs.StringVar(&c.AWSRegion,
		"aws-region",
		c.AWSRegion,
		"aws region of network",
	)
	fs.StringVar(&c.AWSCallerIdentity,
		"aws-caller-identity",
		c.AWSCallerIdentity,
		"aws caller identity arn",
	)

	fs.StringVar(&c.GCPRegion,
		"gcp-region",
		c.GCPRegion,
		"gcp region of network",
	)
	fs.StringVar(&c.Selector,
		"selector",
		c.Selector,
		"selector for cases",
	)
	fs.StringVar(&c.Cloud,
		"cloud",
		c.Cloud,
		"cloud provider, now support eks or gke",
	)
}

func NewDefaultTestConfig() *TestConfig {
	return &TestConfig{
		NamespaceBaseName: "e2e-",
		AWSRegion:         os.Getenv("AWS_REGION"),
		GCPRegion:         os.Getenv("GCP_REGION"),
		Cloud:             "eks",
	}
}
