package iace

// SecondaryHarm models the consequential damage chain triggered by a primary
// hazard. The classical IACE / ISO-12100 model treats Hazard -> Harm as a
// single step ("operator gets crushed"). BreakPilot extends this with a
// follow-on chain so the risk assessment can address:
//
//   - consumer_safety: end customer exposed to defective product
//     (e.g. glass shards in a bottled drink that reaches a supermarket)
//   - product_liability: manufacturer liability under ProdHaftG / EU PLD
//   - food_safety: traceability and recall obligations (VO 178/2002)
//   - environmental: spill, contamination, waste-disposal consequence
//   - reputation: brand damage that escalates to investor / market level
//   - financial: direct cost (lawsuit, recall, fine)
//
// This struct is the data contract; persistence is deferred to a future
// migration. The pattern library can already attach SecondaryHarms to a
// HazardPattern; the API layer surfaces them on hazard generation.
//
// See memory project_attribution_strategy.md plus the "Cola splitter" worked
// example from the IACE strategy discussion (2026-05-20).
type SecondaryHarm struct {
	// Type is one of the SecondaryHarmType* constants below.
	Type string `json:"type"`

	// Description is a single sentence describing the secondary harm
	// scenario in concrete terms ("Splitter in Folgeflasche bei
	// Karussell-Abfueller -> Endkunde verletzt").
	Description string `json:"description"`

	// LegalBasis cites the legal framework that turns the secondary harm
	// into an actionable obligation (e.g. "ProdHaftG §1" or "VO 178/2002
	// Art. 14"). Helps auditors trace the obligation.
	LegalBasis string `json:"legal_basis,omitempty"`

	// SuggestedMitigations is a free-text list of measures specific to
	// the secondary chain (e.g. "Spueltunnel", "Inline-Kamera",
	// "Glasbruchsensor"). Distinct from the primary-mitigations because
	// they protect downstream stakeholders, not the operator.
	SuggestedMitigations []string `json:"suggested_mitigations,omitempty"`

	// Owner identifies the role responsible for handling this secondary
	// harm in the customer organisation. Common values:
	//   "qm" / "product_safety" / "enterprise_risk" / "legal"
	// Empty if responsibility is shared.
	Owner string `json:"owner,omitempty"`
}

// SecondaryHarmType constants — kept short and stable.
const (
	SecondaryHarmConsumerSafety   = "consumer_safety"
	SecondaryHarmProductLiability = "product_liability"
	SecondaryHarmFoodSafety       = "food_safety"
	SecondaryHarmEnvironmental    = "environmental"
	SecondaryHarmReputation       = "reputation"
	SecondaryHarmFinancial        = "financial"
)

// AllSecondaryHarmTypes returns the canonical six categories in the order
// they should appear in UI dropdowns.
func AllSecondaryHarmTypes() []string {
	return []string{
		SecondaryHarmConsumerSafety,
		SecondaryHarmProductLiability,
		SecondaryHarmFoodSafety,
		SecondaryHarmEnvironmental,
		SecondaryHarmReputation,
		SecondaryHarmFinancial,
	}
}

// SecondaryHarmLabelDE returns the human-readable German label.
func SecondaryHarmLabelDE(t string) string {
	switch t {
	case SecondaryHarmConsumerSafety:
		return "Endkundensicherheit"
	case SecondaryHarmProductLiability:
		return "Produkthaftung"
	case SecondaryHarmFoodSafety:
		return "Lebensmittelsicherheit"
	case SecondaryHarmEnvironmental:
		return "Umweltschaden"
	case SecondaryHarmReputation:
		return "Reputation/Marke"
	case SecondaryHarmFinancial:
		return "Finanzieller Schaden"
	}
	return t
}
