import 'dart:convert'; import 'package:overfast_api/client.dart'; import 'package:overfast_api/utils/utils.dart'; enum Gamemode { assault, captureTheFlag, control, deathmatch, elimination, escort, hybrid, push, teamDeathmatch, flashpoint, clash; @override String toString() => toKebabCase(name); static Gamemode fromString(String value) { return Gamemode.values.firstWhere((e) => e.toString() == value); } } final class GameMap { final String name; final List gamemodes; final String screenshot; final String location; final String? countryCode; const GameMap({ required this.name, required this.gamemodes, required this.screenshot, required this.location, this.countryCode, }); // Stub empty constructor GameMap.empty() : this(name: '', gamemodes: [], screenshot: '', location: ''); factory GameMap.fromJson(Map json) { return GameMap( name: json['name'], gamemodes: (json['gamemodes'] as List) .map((e) => Gamemode.fromString(e)) .cast() .toList(), screenshot: json['screenshot'], location: json['location'], countryCode: json['countryCode'], ); } Map toJson() { return { 'name': name, 'gamemode': gamemodes.map((e) => e.toString()).toList(), 'screenshot': screenshot, 'location': location, 'countryCode': countryCode, }; } } final class Maps { final Overfast _client; Maps(this._client); Future> maps({Gamemode? gameMode}) => _client.getList( '/maps', gameMode != null ? {'gamemode': gameMode.toString()} : {}, ); Future> gamemodes() async { // Special case, manual request final response = await _client.client.get( _client.baseUri.replace(path: '/maps/gamemodes'), ); throwIfNecessary(response.statusCode, response.body); return (json.decode(response.body) as List) .map((e) => Gamemode.fromString(e)) .cast() .toList(); } }