package spells

import (
	"crypto/sha256"
	"encoding/hex"
	"encoding/json"
	"fmt"

	"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
	spellcatalog "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/spells/catalog"
)

func newCatalogPromptInput(effective spellcatalog.EffectiveCatalog) (contracts.LLMInputMaterial, error) {
	content, err := json.Marshal(struct {
		Spells []spellcatalog.PromptSpell `json:"spells"`
	}{Spells: effective.PromptSpells()})
	if err != nil {
		return contracts.LLMInputMaterial{}, fmt.Errorf("encode spell recognition catalog: %w", err)
	}
	sum := sha256.Sum256(content)
	digest := "sha256:" + hex.EncodeToString(sum[:])
	return contracts.NewLLMInputMaterial(
		spellcatalog.SpellCatalogReferenceSlot,
		"application/json",
		content,
		digest,
		"",
	), nil
}
