import type { LegacyLifeSession } from "../../hooks/legacySessionTypes";
import {
  createLegacyRunController,
  type LegacyRunController,
} from "../legacy-run/legacyRunController";

export interface LegacyMainPanelHomeModel {
  isReady: boolean;
  selectedTalentCount: number;
  stage: LegacyLifeSession["stage"];
  totals: LegacyLifeSession["totals"];
  trajectoryLength: number;
}

export interface LegacyMainPanelAchievementModel {
  achievementCatalog: LegacyLifeSession["achievementCatalog"];
  totalCards: LegacyLifeSession["totalCards"];
}

export interface LegacyMainPanelThanksModel {
  entries: LegacyLifeSession["specialThanks"];
  onShuffle: LegacyLifeSession["reshuffleSpecialThanks"];
}

export interface LegacyMainPanelModel {
  achievements: LegacyMainPanelAchievementModel;
  home: LegacyMainPanelHomeModel;
  run: LegacyRunController;
  thanks: LegacyMainPanelThanksModel;
}

export function createLegacyMainPanelModel(
  session: LegacyLifeSession,
  onRemake: LegacyLifeSession["remakeLife"] = session.remakeLife,
): LegacyMainPanelModel {
  return {
    achievements: {
      achievementCatalog: session.achievementCatalog,
      totalCards: session.totalCards,
    },
    home: {
      isReady: session.isReady,
      selectedTalentCount: session.selectedTalentIds.length,
      stage: session.stage,
      totals: session.totals,
      trajectoryLength: session.trajectory.length,
    },
    run: createLegacyRunController(session, onRemake),
    thanks: {
      entries: session.specialThanks,
      onShuffle: session.reshuffleSpecialThanks,
    },
  };
}
