/**
 * Isomorphic game validation types
 * Used on both client and server for arcade session validation
 */

import type { MemoryPairsState } from '@/app/games/matching/context/types'

export type GameName = 'matching' | 'memory-quiz' | 'complement-race'

export interface ValidationResult {
  valid: boolean
  error?: string
  newState?: unknown
}

export interface GameMove {
  type: string
  playerId: string
  timestamp: number
  data: unknown
}

// Matching game specific moves
export interface MatchingFlipCardMove extends GameMove {
  type: 'FLIP_CARD'
  data: {
    cardId: string
  }
}

export interface MatchingStartGameMove extends GameMove {
  type: 'START_GAME'
  data: {
    activePlayers: string[] // Player IDs (UUIDs)
    cards?: any[] // GameCard type from context
  }
}

export interface MatchingClearMismatchMove extends GameMove {
  type: 'CLEAR_MISMATCH'
  data: Record<string, never>
}

export type MatchingGameMove =
  | MatchingFlipCardMove
  | MatchingStartGameMove
  | MatchingClearMismatchMove

// Generic game state union
export type GameState = MemoryPairsState // Add other game states as union later

/**
 * Base validator interface that all games must implement
 */
export interface GameValidator<TState = unknown, TMove extends GameMove = GameMove> {
  /**
   * Validate a game move and return the new state if valid
   */
  validateMove(state: TState, move: TMove): ValidationResult

  /**
   * Check if the game is in a terminal state (completed)
   */
  isGameComplete(state: TState): boolean

  /**
   * Get initial state for a new game
   */
  getInitialState(config: unknown): TState
}
