package iace

import (
	_ "embed"
	"encoding/json"
)

// Source-document register for the FMEA failure-knowledge corpus. The manifest
// is generated by the Anthropic extraction run (scripts/fmea_anthropic_extract.py)
// and committed here, so the FMEA frontend can ALWAYS show every source document
// we use — with its source + licence — straight from the deployed binary.
// Each entry is auditable: a public URL + the licence under which we use it.

//go:embed datasources/nasa_failure_sources.json
var failureSourcesJSON []byte

// FailureSourceDoc is one source document in the register.
type FailureSourceDoc struct {
	ID          int64  `json:"id"`
	Title       string `json:"title"`
	Source      string `json:"source"`
	License     string `json:"license"`
	URL         string `json:"url"`
	Used        bool   `json:"used"`      // true = applicable failure, ingested into the corpus
	Component   string `json:"component"` // extracted (empty if not used)
	FailureMode string `json:"failure_mode"`
	Confidence  string `json:"confidence"`
}

// FailureSources is the full register manifest.
type FailureSources struct {
	Generated string             `json:"generated"`
	Model     string             `json:"model"`
	Count     int                `json:"count"`
	Documents []FailureSourceDoc `json:"documents"`
}

// GetFailureSources returns the embedded source-document register.
func GetFailureSources() FailureSources {
	var fs FailureSources
	_ = json.Unmarshal(failureSourcesJSON, &fs)
	if fs.Documents == nil {
		fs.Documents = []FailureSourceDoc{}
	}
	return fs
}
