package register

import (
	"gitea.maximumdirect.net/eric/notarius/internal/core/source"
	"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
	"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
)

func registerEvidence(registry *pipeline.ArtifactEvidenceRegistry) error {
	return runRegistrations([]registration{
		{name: "spells evidence", register: func() error { return pipeline.RegisterArtifactEvidence(registry, dnd.SpellListKind, spellEvidence) }},
		{name: "npc registry evidence", register: func() error { return pipeline.RegisterArtifactEvidence(registry, dnd.NPCRegistryKind, npcEvidence) }},
		{name: "combat turns evidence", register: func() error {
			return pipeline.RegisterArtifactEvidence(registry, dnd.CombatTurnListKind, combatTurnEvidence)
		}},
		{name: "enemy events evidence", register: func() error {
			return pipeline.RegisterArtifactEvidence(registry, dnd.EnemyEventListKind, enemyEventEvidence)
		}},
		{name: "item occurrences evidence", register: func() error {
			return pipeline.RegisterArtifactEvidence(registry, dnd.ItemOccurrenceListKind, itemOccurrenceEvidence)
		}},
		{name: "item registry evidence", register: func() error {
			return pipeline.RegisterArtifactEvidence(registry, dnd.ItemRegistryKind, itemRegistryEvidence)
		}},
		{name: "npc occurrences evidence", register: func() error {
			return pipeline.RegisterArtifactEvidence(registry, dnd.NPCOccurrenceListKind, npcOccurrenceEvidence)
		}},
		{name: "scene descriptions evidence", register: func() error {
			return pipeline.RegisterArtifactEvidence(registry, dnd.SceneDescriptionListKind, sceneDescriptionEvidence)
		}},
		{name: "locations evidence", register: func() error {
			return pipeline.RegisterArtifactEvidence(registry, dnd.LocationRegistryKind, locationEvidence)
		}},
		{name: "location occurrences evidence", register: func() error {
			return pipeline.RegisterArtifactEvidence(registry, dnd.LocationOccurrenceListKind, locationOccurrenceEvidence)
		}},
	})
}

func spellEvidence(value dnd.SpellList) []source.SourceRef {
	var refs []source.SourceRef
	for _, record := range value.SpellCasts {
		refs = append(refs, record.SourceRefs...)
	}
	return append([]source.SourceRef(nil), refs...)
}

func npcEvidence(value dnd.NPCRegistry) []source.SourceRef {
	var refs []source.SourceRef
	for _, record := range value.NPCs {
		refs = append(refs, record.SourceRefs...)
	}
	return append([]source.SourceRef(nil), refs...)
}

func combatTurnEvidence(value dnd.CombatTurnList) []source.SourceRef {
	var refs []source.SourceRef
	for _, record := range value.CombatTurns {
		refs = append(refs, record.SourceRefs...)
	}
	return append([]source.SourceRef(nil), refs...)
}

func enemyEventEvidence(value dnd.EnemyEventList) []source.SourceRef {
	var refs []source.SourceRef
	for _, record := range value.Events {
		refs = append(refs, record.SourceRefs...)
	}
	return append([]source.SourceRef(nil), refs...)
}

func itemOccurrenceEvidence(value dnd.ItemOccurrenceList) []source.SourceRef {
	var refs []source.SourceRef
	for _, record := range value.Occurrences {
		refs = append(refs, record.SourceRefs...)
	}
	return append([]source.SourceRef(nil), refs...)
}

func itemRegistryEvidence(value dnd.ItemRegistry) []source.SourceRef {
	var refs []source.SourceRef
	for _, item := range value.Items {
		refs = append(refs, item.SourceRefs...)
	}
	return append([]source.SourceRef(nil), refs...)
}

func npcOccurrenceEvidence(value dnd.NPCOccurrenceList) []source.SourceRef {
	var refs []source.SourceRef
	for _, record := range value.Occurrences {
		refs = append(refs, record.SourceRefs...)
	}
	return append([]source.SourceRef(nil), refs...)
}

func sceneDescriptionEvidence(value dnd.SceneDescriptionList) []source.SourceRef {
	refs := make([]source.SourceRef, 0, len(value.Scenes))
	for _, record := range value.Scenes {
		refs = append(refs, record.SourceRef)
	}
	return refs
}

func locationEvidence(value dnd.LocationRegistry) []source.SourceRef {
	var refs []source.SourceRef
	for _, location := range value.Locations {
		refs = append(refs, location.SourceRefs...)
	}
	return append([]source.SourceRef(nil), refs...)
}

func locationOccurrenceEvidence(value dnd.LocationOccurrenceList) []source.SourceRef {
	var refs []source.SourceRef
	for _, occurrence := range value.Occurrences {
		refs = append(refs, occurrence.SourceRefs...)
	}
	return append([]source.SourceRef(nil), refs...)
}
