// problem_model.dart import 'dart:convert'; import 'package:problem_check_system/data/models/enum_model.dart'; import 'package:problem_check_system/data/models/image_metadata_model.dart'; class Problem { String? id; String description; String location; List imageUrls; DateTime creationTime; SyncStatus syncStatus; String? censorTaskId; String? bindData; bool isChecked; Problem({ this.id, required this.description, required this.location, required this.imageUrls, required this.creationTime, this.syncStatus = SyncStatus.notSynced, this.censorTaskId, this.bindData, this.isChecked = false, }); // copyWith method to create a new instance with updated values Problem copyWith({ String? id, String? description, String? location, List? imageUrls, DateTime? creationTime, SyncStatus? syncStatus, String? censorTaskId, String? bindData, }) { return Problem( id: id ?? this.id, description: description ?? this.description, location: location ?? this.location, imageUrls: imageUrls ?? this.imageUrls, creationTime: creationTime ?? this.creationTime, syncStatus: syncStatus ?? this.syncStatus, censorTaskId: censorTaskId ?? this.censorTaskId, bindData: bindData ?? this.bindData, ); } // toMap method for serializing to a database-friendly Map Map toMap() { return { 'id': id, 'description': description, 'location': location, 'imageUrls': jsonEncode(imageUrls.map((meta) => meta.toMap()).toList()), 'creationTime': creationTime.millisecondsSinceEpoch, 'syncStatus': syncStatus.index, 'censorTaskId': censorTaskId, 'bindData': bindData, }; } // fromMap factory constructor for deserializing from a Map factory Problem.fromMap(Map map) { return Problem( id: map['id'], description: map['description'], location: map['location'], imageUrls: (jsonDecode(map['imageUrls']) as List) .map((item) => ImageMetadata.fromMap(item as Map)) .toList(), creationTime: DateTime.fromMillisecondsSinceEpoch( map['creationTime'] as int, ), syncStatus: SyncStatus.values[map['syncStatus'] as int], censorTaskId: map['censorTaskId'], bindData: map['bindData'], ); } }