package subscription

import (
	"github.com/tidbcloud/alertstore/pkg/alert"
	"github.com/tidbcloud/alertstore/pkg/event"
)

// The two ways a Target is built, in one place. Every field is a string and
// several are plausible values for each other, so this literal was already
// written out three times — mute check, alert fan-out, event fan-out — with
// nothing but review keeping them identical. The preview would have been a
// fourth, and it is the one that must not drift: a target assembled even
// slightly differently reports a count for a filter nobody will be matched by.

// TargetFromAlert builds the match target for a stored alert, whose attrs are
// frozen at creation — the context it was routed with, not a re-derivation.
func TargetFromAlert(attrs *alert.AlertAttrs) Target {
	return Target{
		Region:         attrs.Region,
		Classification: attrs.Classification,
		Alertname:      attrs.Alertname,
		ClusterID:      attrs.ClusterID,
		TenantID:       attrs.TenantID,
		BizRegion:      attrs.BizRegion,
		TenantKind:     attrs.TenantKind,
		CustomerType:   attrs.CustomerType,
		Component:      attrs.Component,
		Labels:         attrs.Labels,
	}
}

// TargetFromEvent builds the match target for one observation, which the mute
// check and the event fan-out both match against.
func TargetFromEvent(attrs *event.EventAttrs) Target {
	return Target{
		Region:         attrs.Region,
		Classification: attrs.Classification,
		Alertname:      attrs.Alertname,
		ClusterID:      attrs.ClusterID,
		TenantID:       attrs.TenantID,
		BizRegion:      attrs.BizRegion,
		TenantKind:     attrs.TenantKind,
		CustomerType:   attrs.CustomerType,
		Component:      attrs.Component,
		Labels:         attrs.Labels,
	}
}
