// ─── Mind Circuit Definitions ────────────────────────────────────────────
// Behavior logic for golems: basic attacks, spell casting patterns.

import type { MindCircuitDefinition } from './types';
import { elemCost, rawCost } from './types';

const SIMPLE_CIRCUIT: MindCircuitDefinition = {
  id: 'simple',
  name: 'Simple Logic Circuit',
  description: 'Performs basic attacks only. Targets nearest enemy. No spell casting.',
  spellSlots: 0,
  behavior: 'basicOnly',
  summonCost: [elemCost('earth', 3)],
  unlockRequirement: {
    type: 'attunement_level',
    attunement: 'fabricator',
    level: 1,
  },
};

const INTERMEDIATE_CIRCUIT: MindCircuitDefinition = {
  id: 'intermediate',
  name: 'Intermediate Logic Circuit',
  description: 'Casts 1 selected spell when mana is available. Otherwise performs basic attacks.',
  spellSlots: 1,
  behavior: 'castSpell1',
  summonCost: [elemCost('crystal', 8)],
  unlockRequirement: {
    type: 'dual_attunement',
    attunements: ['enchanter', 'fabricator'],
    levels: [2, 3],
  },
};

const ADVANCED_CIRCUIT: MindCircuitDefinition = {
  id: 'advanced',
  name: 'Advanced Logic Circuit',
  description: 'Casts 2 selected spells in alternating order: A → B → A → B... Falls back to basic attacks if mana is insufficient.',
  spellSlots: 2,
  behavior: 'alternate2',
  summonCost: [elemCost('crystal', 12)],
  unlockRequirement: {
    type: 'dual_attunement',
    attunements: ['enchanter', 'fabricator'],
    levels: [3, 4],
  },
};

const GUARDIAN_CIRCUIT: MindCircuitDefinition = {
  id: 'guardian',
  name: 'Guardian Circuit',
  description: 'Required for Guardian Constructs. Cycles through one spell per mana type from the Guardian Core. Falls back to basic attacks if mana is insufficient.',
  spellSlots: 4, // Typically 3-4 depending on guardian
  behavior: 'cycleAll',
  summonCost: [elemCost('crystal', 25), rawCost(10)],
  unlockRequirement: {
    type: 'dual_attunement',
    attunements: ['invoker', 'fabricator'],
    levels: [5, 5],
  },
};

// ─── MIND CIRCUIT REGISTRY ───────────────────────────────────────────────

export const MIND_CIRCUITS: Record<string, MindCircuitDefinition> = {
  [SIMPLE_CIRCUIT.id]: SIMPLE_CIRCUIT,
  [INTERMEDIATE_CIRCUIT.id]: INTERMEDIATE_CIRCUIT,
  [ADVANCED_CIRCUIT.id]: ADVANCED_CIRCUIT,
  [GUARDIAN_CIRCUIT.id]: GUARDIAN_CIRCUIT,
};

export const ALL_MIND_CIRCUITS = [
  SIMPLE_CIRCUIT,
  INTERMEDIATE_CIRCUIT,
  ADVANCED_CIRCUIT,
  GUARDIAN_CIRCUIT,
];
