import { Router } from 'express';
import { saveState } from '../services/SaveState.js';
import { trustSystem } from '../services/TrustSystem.js';
import { progressionSystem } from '../services/ProgressionSystem.js';
import { shiftTimer } from '../services/ShiftTimer.js';
import { narrativePhaseTracker } from '../services/NarrativePhaseTracker.js';
import { hiddenHookTracker } from '../services/HiddenHookTracker.js';
import { endingEvaluator } from '../services/EndingEvaluator.js';

const router = Router();

router.get('/', (_req, res) => {
  const state = saveState.get();
  res.json({
    trust: trustSystem.getScore(),
    shiftNumber: state.shift_number,
    shiftStartedAt: state.shift_started_at,
    shift: shiftTimer.getSnapshot(state),
    worldFlags: state.world_flags,
    progression: progressionSystem._snapshot(),
    certifications: state.certifications,
    currentShiftStats: state.current_shift_stats ?? null,
    shiftHistory: state.shift_history ?? [],
    narrativePhase: narrativePhaseTracker.getPhase(),
    hiddenHooksDiscovered: hiddenHookTracker.getDiscovered(),
    accessLevel: progressionSystem.getAccessLevel(),
    endingTrajectory: endingEvaluator.evaluate()
  });
});

export default router;
