// packages/feature_game_spider/lib/models/spider_game_state.dart
import 'spider_card.dart';

/// 게임 보드 전체의 상태를 저장하는 클래스
class SpiderGameState {
  final List<List<SpiderCard>> tableau;
  final List<SpiderCard> stock;
  final List<List<SpiderCard>> foundation;
  final int moves;
  // ❌ undoCount가 여기서 제거됨

  SpiderGameState({
    required this.tableau,
    required this.stock,
    required this.foundation,
    required this.moves,
  });

  /// `spider.html`의 `undoHistory`에 해당하는
  /// 되돌리기용 복사본을 생성하는 팩토리 생성자
  factory SpiderGameState.fromHistory(SpiderGameHistory history) {
    return SpiderGameState(
      tableau: history.tableau.map((pile) => List.of(pile)).toList(),
      stock: List.of(history.stock),
      foundation: history.foundation.map((pile) => List.of(pile)).toList(),
      moves: history.moves,
      // ❌ undoCount가 여기서 제거됨
    );
  }
}

/// 되돌리기(Undo)를 위해 저장되는 게임 상태의 스냅샷
class SpiderGameHistory {
  final List<List<SpiderCard>> tableau;
  final List<SpiderCard> stock;
  final List<List<SpiderCard>> foundation;
  final int moves;
  // ❌ undoCount가 여기서 제거됨

  SpiderGameHistory({
    required this.tableau,
    required this.stock,
    required this.foundation,
    required this.moves,
  });

  /// 현재 게임 상태(GameState)로부터 스냅샷 생성
  factory SpiderGameHistory.fromState(SpiderGameState state) {
    return SpiderGameHistory(
      tableau: state.tableau.map((pile) => List.of(pile)).toList(),
      stock: List.of(state.stock),
      foundation: state.foundation.map((pile) => List.of(pile)).toList(),
      moves: state.moves,
    );
  }
}