class CompetitionPlayer {
  const CompetitionPlayer({required this.id, required this.name});

  final String id;
  final String name;
}

class CompetitionTeam {
  const CompetitionTeam({
    required this.id,
    required this.name,
    required this.players,
  });

  final String id;
  final String name;
  final List<CompetitionPlayer> players;

  String get playerNames => players.map((player) => player.name).join('、');
}

class CompetitionMatchup {
  const CompetitionMatchup({
    required this.id,
    required this.teamA,
    required this.teamB,
    this.winnerTeamId,
  });

  final String id;
  final CompetitionTeam teamA;
  final CompetitionTeam teamB;
  final String? winnerTeamId;

  CompetitionMatchup copyWith({String? winnerTeamId}) {
    return CompetitionMatchup(
      id: id,
      teamA: teamA,
      teamB: teamB,
      winnerTeamId: winnerTeamId ?? this.winnerTeamId,
    );
  }
}

class CompetitionTeamListItem {
  const CompetitionTeamListItem({
    required this.id,
    required this.eventName,
    required this.itemName,
    required this.groupName,
    required this.matchPlace,
    required this.matchStartTime,
    required this.matchEndTime,
    required this.matchups,
    this.completed = false,
  });

  final String id;
  final String eventName;
  final String itemName;
  final String groupName;
  final String matchPlace;
  final String matchStartTime;
  final String matchEndTime;
  final List<CompetitionMatchup> matchups;
  final bool completed;

  String get title => groupName.isEmpty ? itemName : '$itemName （$groupName）';

  String get scheduleTime => '$matchStartTime-$matchEndTime';

  CompetitionTeamListItem copyWith({List<CompetitionMatchup>? matchups}) {
    return CompetitionTeamListItem(
      id: id,
      eventName: eventName,
      itemName: itemName,
      groupName: groupName,
      matchPlace: matchPlace,
      matchStartTime: matchStartTime,
      matchEndTime: matchEndTime,
      matchups: matchups ?? this.matchups,
      completed: completed,
    );
  }
}

class CompetitionTeamPageResult {
  const CompetitionTeamPageResult({
    required this.items,
    required this.total,
    required this.page,
    required this.pageSize,
  });

  final List<CompetitionTeamListItem> items;
  final int total;
  final int page;
  final int pageSize;

  bool get hasMore => page * pageSize < total;
}
