import 'package:ac_web/Api/Dtos/EReportType.dart'; import 'package:ac_web/Api/JsonReader.dart'; /// Dart counterpart of the backend `ReportDto` returned by `GET /reports`. class ReportDto { const ReportDto({ required this.id, required this.title, required this.author, required this.timestamp, required this.type, required this.text, }); final String id; final String title; final String author; final DateTime timestamp; final EReportType type; final String text; factory ReportDto.fromJson(Map json) { return ReportDto( id: JsonReader.requireString(json, 'Id'), title: JsonReader.optionalString(json, 'Title') ?? '', author: JsonReader.requireString(json, 'Author'), timestamp: JsonReader.requireDateTime(json, 'Timestamp'), type: JsonReader.enumValue( json, 'Type', EReportType.values, (value) => value.wireName, EReportType.unknown, ), text: JsonReader.optionalString(json, 'Text') ?? '', ); } Map toJson() { return { 'Id': id, 'Title': title, 'Author': author, 'Timestamp': timestamp.toIso8601String(), 'Type': type.wireName, 'Text': text, }; } @override String toString() => 'ReportDto(id: $id, title: $title, author: $author, type: ${type.wireName})'; }