package jira

// knownComponents is jiralert's component whitelist, transcribed from its
// `jira.component_map` template. Jira rejects a create that names a component
// the project does not define, so an alert whose `component` label is not one
// of these lands in "other" rather than failing — exactly what jiralert did.
//
// Adding a component to the Jira project means adding it here too. That is the
// cost of a whitelist, and it is the cheaper mistake: the alternative fails the
// whole issue for one unrecognized label.
var knownComponents = map[string]struct{}{
	"account-server":                {},
	"ai-gateway":                    {},
	"aipower":                       {},
	"alertmanager":                  {},
	"api-gateway":                   {},
	"aws-shared-provider":           {},
	"billing-server":                {},
	"br":                            {},
	"cassandra":                     {},
	"central-server":                {},
	"central-worker":                {},
	"cert-manager":                  {},
	"chaos-provider":                {},
	"chaos-svc":                     {},
	"cicd":                          {},
	"clinic":                        {},
	"cloud-finops-system":           {},
	"cluster-autoscaler":            {},
	"cluster-ng-service":            {},
	"config-manager":                {},
	"core-svc":                      {},
	"cost-provider-server":          {},
	"data-migration":                {},
	"dataflow-server":               {},
	"dataflow-service":              {},
	"dataflow-service-ng":           {},
	"dataflow-worker":               {},
	"dataplane-controller":          {},
	"dataservice":                   {},
	"dbaas-proxy":                   {},
	"dedicated-regional-server":     {},
	"devtier-provider":              {},
	"dm":                            {},
	"dm-worker":                     {},
	"drive9":                        {},
	"ecosystem-server":              {},
	"eks-provider":                  {},
	"etcd":                          {},
	"export":                        {},
	"frontend":                      {},
	"gateway":                       {},
	"gitops":                        {},
	"gke-provider":                  {},
	"goldpinger":                    {},
	"import":                        {},
	"import-controller":             {},
	"infra-api":                     {},
	"infra-provider":                {},
	"k8s-pod":                       {},
	"kubernetes":                    {},
	"lightning":                     {},
	"logging":                       {},
	"loki":                          {},
	"manager":                       {},
	"metadb":                        {},
	"metering-server":               {},
	"metrics-integration":           {},
	"metrics-server":                {},
	"mnemos":                        {},
	"network":                       {},
	"next-gen-br":                   {},
	"next-gen-br-kernel":            {},
	"next-gen-export":               {},
	"next-gen-import":               {},
	"ng-auto-scaler":                {},
	"nginx-ingress":                 {},
	"ngmonitoring":                  {},
	"node":                          {},
	"node-exporter":                 {},
	"node-info":                     {},
	"o11y":                          {},
	"observability-global-server":   {},
	"observability-regional-server": {},
	"pd":                            {},
	"prometheus":                    {},
	"quota-exporter":                {},
	"resilience":                    {},
	"serverless-metering":           {},
	"serverless-svc":                {},
	"shared-tier-provider":          {},
	"tcidm-regional":                {},
	"thanos":                        {},
	"ticdc":                         {},
	"ticdc-kernel":                  {},
	"tidb":                          {},
	"tidb-auditlog":                 {},
	"tidb-cluster":                  {},
	"tidb-executor":                 {},
	"tidb-management-service":       {},
	"tidb-operator":                 {},
	"tidb-optimizer":                {},
	"tidb-sql":                      {},
	"tidb-sql-data":                 {},
	"tidb-txn":                      {},
	"tidb-worker":                   {},
	"tiflash":                       {},
	"tikv":                          {},
	"tiproxy":                       {},
	"ue-pd":                         {},
	"ue-test":                       {},
	"ue-ticdc-kernel":               {},
	"ue-tidb-executor":              {},
	"ue-tidb-optimizer":             {},
	"ue-tidb-sql-data":              {},
	"ue-tiflash":                    {},
	"ue-tikv":                       {},
	"vmagent":                       {},
}

// otherComponent is where an unrecognized component label lands.
const otherComponent = "other"

// mapComponent resolves the alert's component label to a component the Jira
// project actually has.
func mapComponent(component string) string {
	if _, ok := knownComponents[component]; ok {
		return component
	}
	return otherComponent
}
