import 'package:overfast_api/client.dart'; import 'package:overfast_api/utils/types.dart'; class PlayerSummary { final String username; final String? avatar; final String? namecard; final String? title; final PlayerEndorsement endorsement; final PlatformCompetitiveRank? competitiveRank; const PlayerSummary({ required this.username, this.avatar, this.namecard, this.title, required this.endorsement, required this.competitiveRank, }); factory PlayerSummary.fromJson(Map json) { return PlayerSummary( username: json['username'], avatar: json['avatar'], namecard: json['namecard'], title: json['title'], endorsement: PlayerEndorsement.fromJson(json['endorsement']), competitiveRank: PlatformCompetitiveRank.fromJson(json['competitive']), ); } Map toJson() { return { 'username': username, 'avatar': avatar, 'namecard': namecard, 'title': title, 'endorsement': endorsement.toJson(), 'competitiveRank': competitiveRank?.toJson(), }; } } class PlayerEndorsement { final int level; final String frame; const PlayerEndorsement({ required this.level, required this.frame, }); factory PlayerEndorsement.fromJson(Map json) { return PlayerEndorsement( level: json['level'], frame: json['frame'], ); } Map toJson() { return { 'level': level, 'frame': frame, }; } } class PlatformCompetitiveRank { final CompetitiveRank? pc; final CompetitiveRank? console; const PlatformCompetitiveRank({ this.pc, this.console, }); factory PlatformCompetitiveRank.fromJson(Map json) { return PlatformCompetitiveRank( pc: json['pc'] != null ? CompetitiveRank.fromJson(json['pc']) : null, console: json['console'] != null ? CompetitiveRank.fromJson(json['console']) : null, ); } Map toJson() { return { 'pc': pc?.toJson(), 'console': console?.toJson(), }; } } class CompetitiveRank { final int season; final RoleDetails? tank; final RoleDetails? damage; final RoleDetails? support; final RoleDetails? openQueue; const CompetitiveRank({ required this.season, required this.tank, required this.damage, required this.support, required this.openQueue, }); factory CompetitiveRank.fromJson(Map json) { return CompetitiveRank( season: json['season'], tank: json['tank'] == null ? null : RoleDetails.fromJson(json['tank']), damage: json['damage'] == null ? null : RoleDetails.fromJson(json['damage']), support: json['support'] == null ? null : RoleDetails.fromJson(json['support']), openQueue: json['open'] == null ? null : RoleDetails.fromJson(json['open']), ); } Map toJson() { return { 'season': season, 'tank': tank?.toJson(), 'damage': damage?.toJson(), 'support': support?.toJson(), }; } } class RoleDetails { final String division; final int tier; final String roleIcon; final String rankIcon; final String tierIcon; const RoleDetails({ required this.division, required this.tier, required this.roleIcon, required this.rankIcon, required this.tierIcon, }); factory RoleDetails.fromJson(Map json) { return RoleDetails( division: json['division'], tier: json['tier'], roleIcon: json['role_icon'], rankIcon: json['rank_icon'], tierIcon: json['tier_icon'], ); } Map toJson() { return { 'division': division, 'tier': tier, 'roleIcon': roleIcon, 'rankIcon': rankIcon, 'tierIcon': tierIcon, }; } } class StatsSummary { final StatsRecap general; final Map heroes; final Map roles; const StatsSummary({ required this.general, required this.heroes, required this.roles, }); factory StatsSummary.fromJson(Map json) { return StatsSummary( general: StatsRecap.fromJson(json['general']), heroes: Map.from(json['heroes']).map( (key, value) => MapEntry(key, StatsRecap.fromJson(value)), ), roles: Map.from(json['roles']).map( (key, value) => MapEntry(key, StatsRecap.fromJson(value)), ), ); } Map toJson() { return { 'general': general.toJson(), 'heroes': heroes.map((key, value) => MapEntry(key, value.toJson())), 'roles': roles.map((key, value) => MapEntry(key, value.toJson())), }; } } class StatsRecap { final int gamesPlayed; final int gamesWon; final int gamesLost; final Duration timePlayed; final double winrate; final double kda; final SubStatsRecap total; final SubStatsRecap average; const StatsRecap({ required this.gamesPlayed, required this.gamesWon, required this.gamesLost, required this.timePlayed, required this.winrate, required this.kda, required this.total, required this.average, }); factory StatsRecap.fromJson(Map json) { return StatsRecap( gamesPlayed: json['games_played'], gamesWon: json['games_won'], gamesLost: json['games_lost'], timePlayed: Duration(seconds: json['time_played']), winrate: json['winrate'], kda: json['kda'], total: SubStatsRecap.fromJson(json['total']), average: SubStatsRecap.fromJson(json['average']), ); } Map toJson() { return { 'games_played': gamesPlayed, 'games_won': gamesWon, 'games_lost': gamesLost, 'time_played': timePlayed.inSeconds, 'winrate': winrate, 'kda': kda, 'total': total.toJson(), 'average': average.toJson(), }; } } class SubStatsRecap { final num eliminations; final num assists; final num deaths; final num damage; final num healing; const SubStatsRecap({ required this.eliminations, required this.assists, required this.deaths, required this.damage, required this.healing, }); factory SubStatsRecap.fromJson(Map json) { return SubStatsRecap( eliminations: json['eliminations'], assists: json['assists'], deaths: json['deaths'], damage: json['damage'], healing: json['healing'], ); } Map toJson() { return { 'eliminations': eliminations, 'assists': assists, 'deaths': deaths, 'damage': damage, 'healing': healing, }; } } class Player { final String playerId; final Overfast _client; const Player(this._client, {required this.playerId}); // I.. don't know how to properly type this. Future career({ Platform? platform, Gamemode gamemode = Gamemode.competitive, HeroKey? hero = HeroKey.allHeroes, }) { return _client.get( '/players/$playerId/stats/career', { if (platform != null) 'platform': platform.toString(), 'gamemode': gamemode.name, if (hero != null) 'hero': hero.toString(), }, ); } Future summary() => _client.get('/players/$playerId/summary'); Future statsSummary() => _client.get('/players/$playerId/stats/summary'); }