// ─── Combat Reset Helper ───────────────────────────────────────────────────────
// Generates the full default combat store state for resetCombat().
// Keeps combatStore.ts under the 400-line limit.

import type { RuntimeActiveGolem } from '../types';
import { getFloorMaxHP } from '../utils';
import { generateSpireFloorState, getRoomsForFloor } from '../utils/spire-utils';
import { makeInitialSpells } from './combat-actions';
import type { CombatState } from './combat-state.types';
import { computeChannelStats } from './combat-channel';

export function createDefaultCombatState(
  startFloor: number,
  spellsToKeep: string[] = [],
): Partial<CombatState> {
  const startSpells = makeInitialSpells(spellsToKeep);
  const seed = startFloor * 12345;
  const rooms = getRoomsForFloor(startFloor, seed);
  const startRoom = generateSpireFloorState(startFloor, 0, rooms, 0);

  return {
    currentFloor: startFloor,
    floorHP: getFloorMaxHP(startFloor),
    floorMaxHP: getFloorMaxHP(startFloor),
    maxFloorReached: startFloor,
    activeSpell: 'manaBolt',
    currentAction: 'meditate',
    castProgress: 0,
    spireMode: false,
    currentRoom: startRoom,
    clearedFloors: {},
    climbDirection: null,
    isDescending: false,
    startFloor,
    exitFloor: startFloor,
    currentRoomIndex: 0,
    roomsPerFloor: rooms,
    runId: 0,
    descentPeak: null,
    roomResetState: {},
    clearedRooms: {},
    isDescentComplete: false,
    golemancy: {
      golemDesigns: {},
      golemLoadout: [],
      activeGolems: [] as RuntimeActiveGolem[],
      lastSummonFloor: 0,
    },
    equipmentSpellStates: [],
    weaponCastProgress: {},
    comboHitCount: 0,
    floorHitCount: 0,
    meleeSwordProgress: {},
    guardianShield: 0,
    guardianShieldMax: 0,
    guardianBarrier: 0,
    guardianBarrierMax: 0,
    spells: startSpells,
    activityLog: [],
    achievements: {
      unlocked: [],
      progress: {},
    },
    totalSpellsCast: 0,
    totalDamageDealt: 0,
    totalCraftsCompleted: 0,

    // Transference Channel defaults (discipline-aware)
    isChanneling: false,
    channelSpeedMultiplier: computeChannelStats().speedMultiplier,
    channelDrainRate: computeChannelStats().drainRate,

    // Room Enchantments defaults
    lastRoomCoverage: 0,
  };
}
