package memory

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

// The Russian read-back vocabulary lives in behavior_ru.json, not in Go source.
//
// It is data, not logic: a weekday name and a verb gloss are wording choices
// that change independently of anything the counter does, and having them as
// literals scattered through behavior.go meant every phrasing tweak was a code
// diff. go:embed keeps the single-binary deploy — the JSON is compiled in, so
// there is no file to install alongside mavend and no way for the two to drift.
//
// Parsed once at init. A malformed file is a panic, deliberately: it can only
// happen if the embedded asset is broken at build time, and a daemon that comes
// up with an empty vocabulary would answer with bare fact keys.

//go:embed behavior_ru.json
var behaviorRUJSON []byte

type behaviorRU struct {
	Weekdays   []string            `json:"weekdays"`
	Activities map[string]string   `json:"activities"`
	KeyAliases map[string][]string `json:"key_aliases"`
}

var (
	// weekdayRU — dative plural, indexed by time.Weekday.
	weekdayRU []string
	// activityRU — canonical fact key to second-person-singular verb phrase.
	activityRU map[string]string
	// canonicalKey — observed fact key to the canonical key it counts as.
	canonicalKey map[string]string
)

func init() {
	var v behaviorRU
	if err := json.Unmarshal(behaviorRUJSON, &v); err != nil {
		panic(fmt.Sprintf("memory: behavior_ru.json: %v", err))
	}
	if len(v.Weekdays) != 7 {
		panic(fmt.Sprintf("memory: behavior_ru.json: want 7 weekdays, got %d", len(v.Weekdays)))
	}
	weekdayRU, activityRU = v.Weekdays, v.Activities
	canonicalKey = make(map[string]string)
	for canonical, variants := range v.KeyAliases {
		canonicalKey[canonical] = canonical
		for _, variant := range variants {
			canonicalKey[variant] = canonical
		}
	}
}
