export interface RunState {
  currentLevel: number;
  coins: number;
  totalCoinsInRun: number;
  totalCoinsOnLevel: number;
  score: number;
  combo: number;
  comboTimer: number;
  projectilesAvailable: number;
  projectileCooldowns: number[];
  activePowerUp: PowerUpType | null;
  powerUpTimer: number;
  hp: number;
  maxHp: number;
  hasUsedSecondChance: boolean;
  enemiesStunned: number;
  timeElapsed: number;
  levelSeed: string;
  isPaused: boolean;
}

export interface MetaState {
  gasCoins: number;
  upgrades: Record<string, number>; // upgradeId -> level
  achievements: string[];
  stats: GlobalStats;
  highScores: HighScore[];
  settings: GameSettings;
}

export interface GlobalStats {
  totalCoinsCollected: number;
  totalEnemiesStunned: number;
  totalDeaths: number;
  totalLevelsCompleted: number;
  totalPlayTime: number;
  highestLevel: number;
  highestCombo: number;
}

export interface HighScore {
  score: number;
  level: number;
  date: number;
  seed?: string;
}

export interface GameSettings {
  musicVolume: number;
  sfxVolume: number;
  screenShake: boolean;
  showFPS: boolean;
}

export type PowerUpType = 'shield' | 'magnet' | 'clock' | 'coffee' | 'infinity' | 'ghost';

export const createInitialRunState = (): RunState => ({
  currentLevel: 1,
  coins: 0,
  totalCoinsInRun: 0,
  totalCoinsOnLevel: 0,
  score: 0,
  combo: 0,
  comboTimer: 0,
  projectilesAvailable: 3,
  projectileCooldowns: [0, 0, 0],
  activePowerUp: null,
  powerUpTimer: 0,
  hp: 1,
  maxHp: 1,
  hasUsedSecondChance: false,
  enemiesStunned: 0,
  timeElapsed: 0,
  levelSeed: '',
  isPaused: false,
});

export const createInitialMetaState = (): MetaState => ({
  gasCoins: 0,
  upgrades: {},
  achievements: [],
  stats: {
    totalCoinsCollected: 0,
    totalEnemiesStunned: 0,
    totalDeaths: 0,
    totalLevelsCompleted: 0,
    totalPlayTime: 0,
    highestLevel: 0,
    highestCombo: 0,
  },
  highScores: [],
  settings: {
    musicVolume: 0.5,
    sfxVolume: 1,
    screenShake: true,
    showFPS: false,
  },
});
