/**
 * 🧠 BRAINY EMBEDDED TYPE EMBEDDINGS
 *
 * AUTO-GENERATED - DO NOT EDIT
 * Generated: 2026-02-09T16:59:48.867Z
 * Noun Types: 42
 * Verb Types: 127
 *
 * This file contains pre-computed embeddings for all NounTypes and VerbTypes.
 * No runtime computation needed, instant availability!
 */

import { NounType, VerbType } from '../types/graphTypes.js'
import { Vector } from '../coreTypes.js'

// Type metadata
export const TYPE_METADATA = {
  nounTypes: 42,
  verbTypes: 127,
  totalTypes: 169,
  embeddingDimensions: 384,
  generatedAt: "2026-02-09T16:59:48.867Z",
  sizeBytes: {
    embeddings: 259584,
    base64: 346112
  }
}

// All noun types in order
const NOUN_TYPE_ORDER: NounType[] = ["person","organization","location","thing","concept","event","agent","organism","substance","quality","timeInterval","function","proposition","document","media","file","message","collection","dataset","product","service","task","project","process","state","role","language","currency","measurement","hypothesis","experiment","contract","regulation","interface","resource","custom","socialGroup","institution","norm","informationContent","informationBearer","relationship"]

// All verb types in order
const VERB_TYPE_ORDER: VerbType[] = ["instanceOf","subclassOf","participatesIn","relatedTo","contains","partOf","references","locatedAt","adjacentTo","precedes","during","occursAt","causes","enables","prevents","dependsOn","requires","creates","transforms","becomes","modifies","consumes","destroys","owns","attributedTo","hasQuality","realizes","affects","composedOf","inherits","memberOf","worksWith","friendOf","follows","likes","reportsTo","mentors","communicates","describes","defines","categorizes","measures","evaluates","uses","implements","extends","equivalentTo","believes","conflicts","synchronizes","competes","canCause","mustCause","wouldCauseIf","couldBe","mustBe","counterfactual","knows","doubts","desires","intends","fears","loves","hates","hopes","perceives","learns","probablyCauses","uncertainRelation","correlatesWith","approximatelyEquals","greaterThan","similarityDegree","moreXThan","hasDegree","partiallyHas","carries","encodes","obligatedTo","permittedTo","prohibitedFrom","shouldDo","mustNotDo","trueInContext","perceivedAs","interpretedAs","validInFrame","trueFrom","overlaps","immediatelyAfter","eventuallyLeadsTo","simultaneousWith","hasDuration","recurringWith","containsSpatially","overlapsSpatially","surrounds","connectedTo","above","below","inside","outside","facing","represents","embodies","opposes","alliesWith","conformsTo","measuredIn","convertsTo","hasMagnitude","dimensionallyEquals","persistsThrough","gainsProperty","losesProperty","remainsSame","functionalPartOf","topologicalPartOf","temporalPartOf","conceptualPartOf","rigidlyDependsOn","functionallyDependsOn","historicallyDependsOn","endorses","contradicts","supports","supersedes"]

// Pre-computed embeddings (338.0KB base64)
const EMBEDDINGS_BASE64 = "[encoded data, 346112 characters]"

// Decode embeddings at startup (happens once, <10ms)
function decodeEmbeddings(): Uint8Array {
  if (typeof Buffer !== 'undefined') {
    // Node.js environment
    return Buffer.from(EMBEDDINGS_BASE64, 'base64')
  } else if (typeof atob !== 'undefined') {
    // Browser environment
    const binaryString = atob(EMBEDDINGS_BASE64)
    const bytes = new Uint8Array(binaryString.length)
    for (let i = 0; i < binaryString.length; i++) {
      bytes[i] = binaryString.charCodeAt(i)
    }
    return bytes
  }
  return new Uint8Array(0)
}

// Cached decoded embeddings
let decodedEmbeddings: Uint8Array | null = null

/**
 * Get noun type embeddings as a Map for fast lookup
 * This is called once and cached
 */
export function getNounTypeEmbeddings(): Map<NounType, Vector> {
  if (!decodedEmbeddings) {
    decodedEmbeddings = decodeEmbeddings()
  }

  const embeddings = new Map<NounType, Vector>()
  const view = new DataView(decodedEmbeddings.buffer)
  const embeddingSize = 384

  NOUN_TYPE_ORDER.forEach((type, index) => {
    const offset = index * embeddingSize * 4
    const embedding = new Float32Array(embeddingSize)

    for (let i = 0; i < embeddingSize; i++) {
      embedding[i] = view.getFloat32(offset + i * 4, true)
    }

    embeddings.set(type, Array.from(embedding))
  })

  return embeddings
}

/**
 * Get verb type embeddings as a Map for fast lookup
 * This is called once and cached
 */
export function getVerbTypeEmbeddings(): Map<VerbType, Vector> {
  if (!decodedEmbeddings) {
    decodedEmbeddings = decodeEmbeddings()
  }

  const embeddings = new Map<VerbType, Vector>()
  const view = new DataView(decodedEmbeddings.buffer)
  const embeddingSize = 384

  // Verb embeddings start after noun embeddings
  const verbStartOffset = 42 * embeddingSize * 4

  VERB_TYPE_ORDER.forEach((type, index) => {
    const offset = verbStartOffset + index * embeddingSize * 4
    const embedding = new Float32Array(embeddingSize)

    for (let i = 0; i < embeddingSize; i++) {
      embedding[i] = view.getFloat32(offset + i * 4, true)
    }

    embeddings.set(type, Array.from(embedding))
  })

  return embeddings
}

// Import logging
import { prodLog } from '../utils/logger.js'
prodLog.info(`🧠 Brainy Type Embeddings loaded: ${TYPE_METADATA.nounTypes} nouns, ${TYPE_METADATA.verbTypes} verbs, ${(TYPE_METADATA.sizeBytes.embeddings / 1024).toFixed(1)}KB`)
