|
|
|
// 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<ImageMetadata> 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<ImageMetadata>? 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<String, dynamic> 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<String, dynamic> 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<String, dynamic>))
|
|
|
|
.toList(),
|
|
|
|
creationTime: DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
map['creationTime'] as int,
|
|
|
|
),
|
|
|
|
syncStatus: SyncStatus.values[map['syncStatus'] as int],
|
|
|
|
censorTaskId: map['censorTaskId'],
|
|
|
|
bindData: map['bindData'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|