import 'package:asciineverdie/src/core/model/cumulative_statistics.dart';
import 'package:asciineverdie/src/core/model/session_statistics.dart';

// 하위 호환성(backward compatibility)을 위한 re-export
export 'package:asciineverdie/src/core/model/cumulative_statistics.dart';
export 'package:asciineverdie/src/core/model/session_statistics.dart';

/// 게임 통계 (Game Statistics)
///
/// 세션 및 누적 통계를 추적하는 모델.
/// 세부 구현은 SessionStatistics와 CumulativeStatistics로 분리됨.
class GameStatistics {
  const GameStatistics({required this.session, required this.cumulative});

  /// 현재 세션 통계
  final SessionStatistics session;

  /// 누적 통계
  final CumulativeStatistics cumulative;

  /// 빈 통계
  factory GameStatistics.empty() => GameStatistics(
    session: SessionStatistics.empty(),
    cumulative: CumulativeStatistics.empty(),
  );

  /// 새 세션 시작 (세션 통계 초기화, 누적 통계 유지)
  GameStatistics startNewSession() {
    return GameStatistics(
      session: SessionStatistics.empty(),
      cumulative: cumulative,
    );
  }

  /// 세션 종료 시 누적 통계 업데이트
  GameStatistics endSession() {
    return GameStatistics(
      session: session,
      cumulative: cumulative.mergeSession(session),
    );
  }

  GameStatistics copyWith({
    SessionStatistics? session,
    CumulativeStatistics? cumulative,
  }) {
    return GameStatistics(
      session: session ?? this.session,
      cumulative: cumulative ?? this.cumulative,
    );
  }

  /// JSON 직렬화
  Map<String, dynamic> toJson() {
    return {'session': session.toJson(), 'cumulative': cumulative.toJson()};
  }

  /// JSON 역직렬화
  factory GameStatistics.fromJson(Map<String, dynamic> json) {
    return GameStatistics(
      session: SessionStatistics.fromJson(
        json['session'] as Map<String, dynamic>? ?? {},
      ),
      cumulative: CumulativeStatistics.fromJson(
        json['cumulative'] as Map<String, dynamic>? ?? {},
      ),
    );
  }
}
