package constant

import "github.com/shopspring/decimal"

var (
	DolloarToCents     = decimal.NewFromInt(100) /* 100 cents per dollar */
	MaxSpendLimitValue = uint32(1000000)         /* $10000 */
)

const (
	BillingLabelTenantID    = "tenantID"
	BillingLabelProjectID   = "projectID"
	BillingLabelProjectName = "project"
	BillingLabelClusterID   = "clusterID"
	BillingLabelClusterName = "cluster"
	BillingLabelBranchID    = "branchID"
	BillingLabelBranchName  = "branch"
	BillingLabelRegion      = "region"
	BillingLabelServerless  = "serverless"
	BillingLabelMetricName  = "metric"
	BillingLabelSkuPlan     = "skuPlan"
	BillingLabelWorker      = "worker"

	/* for beta feature */
	BillingLabelBetaKey         = "beta" /* used for beta phase, removal or 'disable' upon official release */
	BillingLabelBetaEnable      = "true"
	BillingLabelBetaCategoryKey = "beta-category" /* used for beta phase, removal upon official release */

	/* used to distinguish the owner of billing record */
	BillingLabelComponent   = "Component"
	BillingComponentTiFlash = "tiflash"

	BillingBetaCategoryBranching = "Branching"
	BillingBetaCategoryPiTR      = "PiTR"
	BillingBetaCategoryTiFlash   = "TiFlash"

	TidbPoolNameFree  = "tidb-pool"
	TidbPoolNameVip   = "vip-tidb-pool"
	TidbPoolNameSuper = "super-vip-tidb-pool"

	RuLimitModeStandard  = "standard"
	RuLimitModeThrottled = "throttled"

	ServerlessFreeQuotaRequestUnit   = 50000000 // 50 Million Request Units free every month
	ServerlessFreeQuotaRowStorage    = 5120     // MiB, 5GiB storage free forever
	ServerlessFreeQuotaColumnStorage = 5120     // MiB, 5GiB storage free forever
)

const (
	EventTypeUpdateSpendingLimit = "UpdateSpendingLimit"
	EventTypeResourceLimitation  = "ResourceLimitation"

	EventSummaryUpdateSpendingLimit = "%s.\nThe cluster is in %s plan."
	EventSummaryResourceLimitation  = "%s.\nRU Mode: %s\nNote: %s. %s."
	EventSummaryRCURestriction      = "The configured maximum RCU consumption has been reached several times in the past hour. Any usage above this limit will be throttled. To prevent any impact on the service, please increase the maximum RCU quota promptly."
)

var (
	EventSummaryRUMode = map[string]string{
		RuLimitModeStandard:  "This cluster has not been throttled",
		RuLimitModeThrottled: "This cluster has been throttled",
	}
	EventDetailsSpendLimitEvents = map[string]string{
		SpendLimitEventStatusFit:              "Spending Limit adequate",
		SpendLimitEventStatusExcessive:        "Spending Limit exhausted",
		SpendLimitEventStatusHandy:            "Spending Limit update",
		SpendLimitEventStatusCreateCluster:    "Spending Limit update",
		SpendLimitEventStatusModifySpendLimit: "Spending Limit update",
	}
	EventDetailsResourceLimitation = map[string]string{
		TidbPoolNameVip + RuLimitModeStandard:   "Under the budget specified by Spending Limit",
		TidbPoolNameVip + RuLimitModeThrottled:  "Used up all the budget specified by Spending Limit, please increase the Monthly Spending Limit to match the resources your application needs",
		TidbPoolNameFree + RuLimitModeStandard:  "Under the budget specified by Free Quota, consider setting the Monthly Spending Limit to match the resources your application needs",
		TidbPoolNameFree + RuLimitModeThrottled: "Used up all the budget specified by Free Quota, please set the Monthly Spending Limit to match the resources your application needs",
	}
	BillingRechargePlanId = map[string]uint{
		"aws/us-east-1":      500000,
		"aws/us-west-2":      500001,
		"aws/eu-central-1":   500002,
		"aws/ap-southeast-1": 500003,
		"aws/ap-northeast-1": 500004,
	}
)

type MetricType string

const (
	MetricTypeTikvStorage                   MetricType = "tikv_storage"
	MetricTypeTiflashStorage                MetricType = "tiflash_storage"
	MetricTypeTidbRU                        MetricType = "tidb_ru"
	MetricTypeExportRU                      MetricType = "export_ru"
	MetricTypeLoadDataRU                    MetricType = "load_data_ru"
	MetricTypeTiflashRU                     MetricType = "tiflash_ru"
	MetricTypePublicEgress                  MetricType = "public_egress"
	MetricTypeTikvStorageWithoutQuantile    MetricType = "tikv_storage_without_quantile"
	MetricTypeTiflashStorageWithoutQuantile MetricType = "tiflash_storage_without_quantile"
)

func (mt MetricType) String() string {
	return string(mt)
}

func (mt MetricType) IsStorageMetric() bool {
	return mt == MetricTypeTikvStorage || mt == MetricTypeTiflashStorage
}

func (mt MetricType) IsTrafficMetric() bool {
	return mt == MetricTypePublicEgress
}

type SkuType string

const (
	SkuTypeRowStorage          SkuType = "row_storage"
	SkuTypeColumnStorage       SkuType = "column_storage"
	SkuTypeRequestUnit         SkuType = "request_unit"
	SkuTypeRequestCapacityUnit SkuType = "request_capacity_unit"

	// Instance Capacity SKU types — one per pricing tier
	SkuTypeInstanceCapacityFree  SkuType = "instance_capacity_free"
	SkuTypeInstanceCapacityTier1 SkuType = "instance_capacity_tier1"
	SkuTypeInstanceCapacityTier2 SkuType = "instance_capacity_tier2"
	SkuTypeInstanceCapacityTier3 SkuType = "instance_capacity_tier3"
	SkuTypeInstanceCapacityTier4 SkuType = "instance_capacity_tier4"
)

// Instance Capacity tier boundaries (active clusters + branches)
const (
	InstanceCapacityFreeLimit  int64 = 100     // 1-100: free
	InstanceCapacityTier1Limit int64 = 5000    // 101-5000
	InstanceCapacityTier2Limit int64 = 100000  // 5001-100000
	InstanceCapacityTier3Limit int64 = 500000  // 100001-500000
	InstanceCapacityTier4Limit int64 = 1000000 // 500001-1000000
)

var (
	SkuAliasNameTypeToString = map[SkuType]string{
		SkuTypeRowStorage:            "row_storage",
		SkuTypeColumnStorage:         "column_storage",
		SkuTypeRequestUnit:           "request_unit",
		SkuTypeRequestCapacityUnit:   "request_capacity_unit",
		SkuTypeInstanceCapacityFree:  "instance_capacity_free",
		SkuTypeInstanceCapacityTier1: "instance_capacity_tier1",
		SkuTypeInstanceCapacityTier2: "instance_capacity_tier2",
		SkuTypeInstanceCapacityTier3: "instance_capacity_tier3",
		SkuTypeInstanceCapacityTier4: "instance_capacity_tier4",
	}
	SkuAliasNameStringToType = map[string]SkuType{
		"row_storage":             SkuTypeRowStorage,
		"column_storage":          SkuTypeColumnStorage,
		"request_unit":            SkuTypeRequestUnit,
		"request_capacity_unit":   SkuTypeRequestCapacityUnit,
		"instance_capacity_free":  SkuTypeInstanceCapacityFree,
		"instance_capacity_tier1": SkuTypeInstanceCapacityTier1,
		"instance_capacity_tier2": SkuTypeInstanceCapacityTier2,
		"instance_capacity_tier3": SkuTypeInstanceCapacityTier3,
		"instance_capacity_tier4": SkuTypeInstanceCapacityTier4,
	}
)

func (st SkuType) String() string {
	return string(st)
}

type ClusterType string

const (
	ClusterTypeCluster ClusterType = "cluster"
	ClusterTypeBranch  ClusterType = "branch"
)
