import '../../domain/entities/server.dart'; class ServerModel { final String id; final String alias; final String host; final String user; final String password; final bool enabled; final bool deactivateEcho; final bool deactivateLiveCheck; final String serverType; // "gcore" or "geviscope" ServerModel({ required this.id, required this.alias, required this.host, required this.user, required this.password, required this.enabled, required this.deactivateEcho, required this.deactivateLiveCheck, required this.serverType, }); factory ServerModel.fromJson(Map json, String type) { return ServerModel( id: json['id'].toString(), alias: json['alias'] as String, host: json['host'] as String, user: json['user'] as String, password: json['password'] as String, enabled: json['enabled'] as bool, deactivateEcho: json['deactivate_echo'] as bool, deactivateLiveCheck: json['deactivate_live_check'] as bool, serverType: type, ); } Map toJson() { return { 'id': id, 'alias': alias, 'host': host, 'user': user, 'password': password, 'enabled': enabled, 'deactivate_echo': deactivateEcho, 'deactivate_live_check': deactivateLiveCheck, }; } Server toEntity() { return Server( id: id, alias: alias, host: host, user: user, password: password, enabled: enabled, deactivateEcho: deactivateEcho, deactivateLiveCheck: deactivateLiveCheck, type: serverType == 'gcore' ? ServerType.gcore : ServerType.geviscope, ); } factory ServerModel.fromEntity(Server server) { return ServerModel( id: server.id, alias: server.alias, host: server.host, user: server.user, password: server.password, enabled: server.enabled, deactivateEcho: server.deactivateEcho, deactivateLiveCheck: server.deactivateLiveCheck, serverType: server.type == ServerType.gcore ? 'gcore' : 'geviscope', ); } }