package framework

import (
	"os"

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

type TestConfig struct {
	Environment config.Config

	NamespaceBaseName string

	InfraAPICRDPaths []string

	InfraClusterTable string

	KubeClusterNameBase string

	AWSRegion string

	TiDBPoolNamespace string

	Selector 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.InfraClusterTable,
		"infra-cluster-table",
		c.InfraClusterTable,
		"infra cluster table in dynamodb",
	)
	fs.StringVar(&c.Environment.User.Kubeconfig,
		"infra-kubeconfig",
		c.Environment.User.Kubeconfig,
		"(deprecated, alias for --kubeconfig) config of infra kubernetes cluster")
	fs.StringVar(&c.Environment.User.Context,
		"infra-context",
		c.Environment.User.Context,
		"(deprecated, alias for --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.TiDBPoolNamespace,
		"tidb-pool-ns",
		c.TiDBPoolNamespace,
		"The tidb pod pool namespace",
	)
	fs.StringVar(&c.Selector,
		"selector",
		c.Selector,
		"selector for cases",
	)
}

func NewDefaultTestConfig() *TestConfig {
	return &TestConfig{
		NamespaceBaseName: "e2e-",
		AWSRegion:         os.Getenv("AWS_REGION"),
		TiDBPoolNamespace: "tidb-pool",
	}
}
