Files
game-tracker/lib/data/dto/match.dart
gelbeinhalb acf3a7b003 Merge remote-tracking branch 'origin/development' into feature/88-neue-datenbank-struktur
# Conflicts:
#	lib/data/dao/group_match_dao.dart
#	lib/data/dao/match_dao.dart
#	lib/data/dao/player_match_dao.dart
#	lib/data/db/database.dart
#	lib/data/db/database.g.dart
#	lib/data/db/tables/group_match_table.dart
#	lib/data/db/tables/player_match_table.dart
#	lib/data/dto/match.dart
#	lib/presentation/views/main_menu/home_view.dart
#	lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart
#	lib/presentation/views/main_menu/match_view/match_view.dart
#	lib/services/data_transfer_service.dart
#	test/db_tests/game_test.dart
#	test/db_tests/group_match_test.dart
#	test/db_tests/player_match_test.dart
2026-02-01 15:55:06 +01:00

55 lines
1.7 KiB
Dart

import 'package:clock/clock.dart';
import 'package:tallee/data/dto/group.dart';
import 'package:tallee/data/dto/player.dart';
import 'package:uuid/uuid.dart';
class Match {
final String id;
final DateTime createdAt;
final String name;
final Game game;
final Group? group;
final List<Player>? players;
final String notes;
Player? winner;
Match({
String? id,
DateTime? createdAt,
required this.name,
required this.game,
this.group,
this.players,
required this.notes,
this.winner,
}) : id = id ?? const Uuid().v4(),
createdAt = createdAt ?? clock.now();
@override
String toString() {
return 'Match{id: $id, name: $name, game: $game, group: $group, players: $players, notes: $notes}';
}
/// Creates a Match instance from a JSON object (ID references format).
/// Related objects are reconstructed from IDs by the DataTransferService.
Match.fromJson(Map<String, dynamic> json)
: id = json['id'],
createdAt = DateTime.parse(json['createdAt']),
name = json['name'],
game = Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: '', icon: ''), // Populated during import via DataTransferService
group = null, // Populated during import via DataTransferService
players = [], // Populated during import via DataTransferService
notes = json['notes'] ?? '';
/// Converts the Match instance to a JSON object using normalized format (ID references only).
Map<String, dynamic> toJson() => {
'id': id,
'createdAt': createdAt.toIso8601String(),
'name': name,
'gameId': game.id,
'groupId': group?.id,
'playerIds': (players ?? []).map((player) => player.id).toList(),
'notes': notes,
};
}