/**
 * BaoLife Events System
 * ====================
 *
 * This package contains all game events organized into logical categories.
 *
 * Package Structure:
 * - base: Core event classes and helper functions
 * - childhood: Events for ages 0-12 (milestones, activities)
 * - adolescence: Events for ages 10-18 (puberty, social development)
 * - education: School, college, and educational events
 * - adulthood: Career, romance, and family events
 * - family: Family relationships, activities, and conflicts
 * - holidays: Annual holidays and special celebrations
 * - school_year: School transitions and grade progression
 * - health: Health, injuries, and medical events
 * - random: Unexpected positive and negative events
 * - negative: Major life crises and severe negative events
 * - dilemmas: Complex moral and ethical choices
 * - conversations: NPC conversation system
 * - tutorial: Tutorial mode events for new players
 */

// Base event classes and helpers
export * from './base.js';

// Tutorial events (for new players in first 24 hours)
export * from './tutorial/index.js';

// Childhood events
export * from './childhood/index.js';

// Adolescence events
export * from './adolescence/index.js';

// Negative events (major crises)
export * from './negative/index.js';

// Education events
export * from './education/index.js';

// Adulthood events
export * from './adulthood/index.js';

// Holiday events
export * from './holidays/index.js';

// Health events
export * from './health/index.js';

// Random events
export * from './random/index.js';

// Family events (activities, conflicts, life transitions)
export * from './family/index.js';

// Relationship events (random weekly events for romantic relationships)
export * from './relationships/index.js';

// School year events (transitions, grade progression)
// Note: Not using `export *` to avoid name conflicts with existing categories
export { schoolYearEvents } from './school_year/school_year_events.js';
export { transitionEvents } from './school_year/transitions.js';

// Dilemma events (moral and ethical choices)
// Note: Not using `export *` to avoid name conflicts with negative/ category
export { dilemmaEvents } from './dilemmas/moral_choices.js';

// Activity events (class-based: career, physical, creative, etc.)
// Note: Not using `export *` to avoid name conflicts with family/ and social/
export { allActivityEvents } from './activities/index.js';

// Social events (class-based: community, gaming, clubs, volunteering)
export { socialEvents as socialClassEvents } from './social/index.js';

// Friendship events (function-based and class-based)
export { friendshipEvents, friendshipClassEvents } from './social/friendships.js';

// Daily disruption events
export { dailyDisruptionEvents } from './random/dailyDisruptions.js';

// Career events (workplace + milestones)
export { workplaceEvents } from './career/index.js';
export { careerMilestoneClassEvents } from './career/index.js';

// Event mode type
import type { EventMode } from './base.js';

/**
 * Mode overrides for function-based events.
 * Events not listed here default to 'both' (fire at any speed).
 * Use 'realtime' for events that should only fire at slow speeds (gameSpeed >= 1000).
 * Use 'fast' for events that should only fire at fast speeds (gameSpeed < 1000).
 */
export const eventModeOverrides: Record<string, EventMode> = {
  // Holidays default to 'both' — explicitly tagged for documentation
  christmas: 'both',

  // ── School Social Events (realtime: small in-the-moment interactions) ──
  tutoringRequest: 'realtime',
  cafeteriaSocialChoice: 'realtime',
  cheatingOpportunity: 'realtime',
  foundWalletSchool: 'realtime',
  groupProject: 'realtime',
  lockerRoomGossip: 'realtime',
  talentShow: 'realtime',
  sportsTryouts: 'realtime',
  teacherConflict: 'realtime',
  libraryDiscovery: 'realtime',

  // ── School Milestone Events (fast: bigger life moments) ──
  reportCardDay: 'fast',
  schoolDance: 'fast',
  promEvent: 'fast',
  scienceFair: 'fast',
  schoolBullying: 'fast',
  classPresident: 'fast',
  detention: 'fast',
  collegePrep: 'fast',
  graduationDay: 'fast',

  // ── Birthday Events (both: date-triggered, fire at any speed) ──
  sweet16: 'both',
  eighteenthBirthday: 'both',
  twentyFirstBirthday: 'both',
  decadeBirthday: 'both',
  birthdayGifts: 'both',

  // ── Enhanced Holiday Events (both: date-triggered, fire at any speed) ──
  newYearResolutionEnhanced: 'both',
  valentinesDayEnhanced: 'both',
  halloweenEnhanced: 'both',
  thanksgivingDinner: 'both',
  christmasEnhanced: 'both',
  summerSolstice: 'both',
  firstDayAutumn: 'both',
  fourthOfJulyEnhanced: 'both',

  // ── Workplace Events (realtime: daily office moments) ──
  coffeeMachineChat: 'realtime',
  bossStressed: 'realtime',
  lunchInvitation: 'realtime',
  deadlinePressure: 'realtime',
  officeBirthday: 'realtime',
  coworkerAskingHelp: 'realtime',
  parkingLotConversation: 'realtime',

  // ── Health Narrative Events (realtime: daily wellness moments) ──
  feelingTiredWarning: 'realtime',
  annualCheckupReminder: 'realtime',
  greatWorkout: 'realtime',
  stressWarning: 'realtime',
  healthyEatingChoice: 'realtime',
  gymBuddyInvite: 'realtime',

  // ── Health Fast Events (fast: bigger medical arcs) ──
  injuryFromActivityHealth: 'fast',
  mentalHealthCrisis: 'fast',
  addictionWarning: 'fast',

  // ── Family Dynamics Events (realtime: daily family interactions) ──
  parentCalls: 'realtime',
  siblingMemory: 'realtime',
  parentNeedsHelp: 'realtime',
  kidDrawing: 'realtime',
  familyGroupChat: 'realtime',
  unexpectedFamilyVisit: 'realtime',
};

// Re-export for convenience
import { childhoodEvents } from './childhood/index.js';
import { adolescenceEvents } from './adolescence/index.js';
import { negativeEvents } from './negative/index.js';
import * as educationEvents from './education/index.js';
import * as adulthoodEvents from './adulthood/index.js';
import * as holidayEvents from './holidays/index.js';
import * as healthEvents from './health/index.js';
import * as randomEvents from './random/index.js';
import { familyEvents } from './family/index.js';
import { randomRelationshipEvents } from './relationships/index.js';
import { tutorialEvents } from './tutorial/index.js';
import { schoolYearEvents } from './school_year/school_year_events.js';
import { transitionEvents } from './school_year/transitions.js';
import { dilemmaEvents } from './dilemmas/moral_choices.js';
import { allActivityEvents } from './activities/index.js';
import { socialEvents } from './social/index.js';
import { friendshipEvents, friendshipClassEvents } from './social/friendships.js';
import { dailyDisruptionEvents } from './random/dailyDisruptions.js';
import { workplaceEvents } from './career/index.js';
import { careerMilestoneClassEvents } from './career/index.js';
import { healthNarrativeEvents } from './health/healthEvents.js';
import { medicalArcClassEvents } from './health/medicalArcs.js';
import { familyDynamicsEvents } from './family/familyDynamics.js';
import { familyMilestoneClassEvents } from './family/familyMilestones.js';

/**
 * Only actual event functions from randomRelationshipEvents.
 * Excludes helper functions (processWeeklyRelationshipEvents, hasActiveRomance,
 * getRelationshipHealth, getAllRandomEvents) that return non-event values.
 */
const relationshipEventFunctions = {
  handleRandomRelationshipEvents: randomRelationshipEvents.handleRandomRelationshipEvents,
};

/**
 * All registered function-based events for the game loop
 * @deprecated Active runtime prompts and resolutions come from events/v2 catalog.
 */
export const allEvents = {
  ...childhoodEvents,
  ...adolescenceEvents,
  ...negativeEvents,
  ...educationEvents,
  ...adulthoodEvents,
  ...holidayEvents,
  ...healthEvents,
  ...randomEvents,
  ...familyEvents,
  ...relationshipEventFunctions,
  ...tutorialEvents,
  ...schoolYearEvents,
  ...transitionEvents,
  ...dilemmaEvents,
  ...friendshipEvents,
  ...dailyDisruptionEvents,
  ...workplaceEvents,
  ...healthNarrativeEvents,
  ...familyDynamicsEvents,
};

/**
 * Class-based events (activities, social) that use BaseEvent architecture.
 * These need to be checked separately from function-based events.
 */
export const classBasedEvents = [
  ...allActivityEvents,
  ...socialEvents,
  ...friendshipClassEvents,
  ...careerMilestoneClassEvents,
  ...medicalArcClassEvents,
  ...familyMilestoneClassEvents,
];

/**
 * Event category to event function mapping
 */
export const eventCategories = {
  childhood: childhoodEvents,
  adolescence: adolescenceEvents,
  negative: negativeEvents,
  education: educationEvents,
  adulthood: adulthoodEvents,
  holidays: holidayEvents,
  health: healthEvents,
  random: randomEvents,
  family: familyEvents,
  relationships: relationshipEventFunctions,
  tutorial: tutorialEvents,
  school_year: { ...schoolYearEvents, ...transitionEvents },
  dilemmas: dilemmaEvents,
} as const;

export type EventCategory = keyof typeof eventCategories;
