class TaskModel { final DateTime assignmentDate; final DateTime? reportedDate; final String id; final WorkItem? workItem; final String workItemId; final double plannedTask; final double completedTask; final AssignedBy assignedBy; final AssignedBy? approvedBy; final List teamMembers; final List comments; final List reportedPreSignedUrls; TaskModel({ required this.assignmentDate, this.reportedDate, required this.id, required this.workItem, required this.workItemId, required this.plannedTask, required this.completedTask, required this.assignedBy, this.approvedBy, required this.teamMembers, required this.comments, required this.reportedPreSignedUrls, }); factory TaskModel.fromJson(Map json) { return TaskModel( assignmentDate: DateTime.parse(json['assignmentDate']), reportedDate: json['reportedDate'] != null ? DateTime.tryParse(json['reportedDate']) : null, id: json['id'], workItem: json['workItem'] != null ? WorkItem.fromJson(json['workItem']) : null, workItemId: json['workItemId'], plannedTask: (json['plannedTask'] as num).toDouble(), completedTask: (json['completedTask'] as num).toDouble(), assignedBy: AssignedBy.fromJson(json['assignedBy']), approvedBy: json['approvedBy'] != null ? AssignedBy.fromJson(json['approvedBy']) : null, teamMembers: (json['teamMembers'] as List) .map((e) => TeamMember.fromJson(e)) .toList(), comments: (json['comments'] as List).map((e) => Comment.fromJson(e)).toList(), reportedPreSignedUrls: (json['reportedPreSignedUrls'] as List?) ?.map((e) => e.toString()) .toList() ?? [], ); } } class WorkItem { final String? id; final ActivityMaster? activityMaster; final WorkArea? workArea; final double? plannedWork; final double? completedWork; final List preSignedUrls; WorkItem({ this.id, this.activityMaster, this.workArea, this.plannedWork, this.completedWork, this.preSignedUrls = const [], }); factory WorkItem.fromJson(Map json) { return WorkItem( id: json['id']?.toString(), activityMaster: json['activityMaster'] != null ? ActivityMaster.fromJson(json['activityMaster']) : null, workArea: json['workArea'] != null ? WorkArea.fromJson(json['workArea']) : null, plannedWork: (json['plannedWork'] as num?)?.toDouble(), completedWork: (json['completedWork'] as num?)?.toDouble(), preSignedUrls: (json['preSignedUrls'] as List?) ?.map((e) => e.toString()) .toList() ?? [], ); } } class ActivityMaster { final String? id; // ✅ Added final String activityName; ActivityMaster({ this.id, required this.activityName, }); factory ActivityMaster.fromJson(Map json) { return ActivityMaster( id: json['id']?.toString(), activityName: json['activityName'] ?? '', ); } } class WorkArea { final String? id; // ✅ Added final String areaName; final Floor? floor; WorkArea({ this.id, required this.areaName, this.floor, }); factory WorkArea.fromJson(Map json) { return WorkArea( id: json['id']?.toString(), areaName: json['areaName'] ?? '', floor: json['floor'] != null ? Floor.fromJson(json['floor']) : null, ); } } class Floor { final String floorName; final Building? building; Floor({required this.floorName, this.building}); factory Floor.fromJson(Map json) { return Floor( floorName: json['floorName'] ?? '', building: json['building'] != null ? Building.fromJson(json['building']) : null, ); } } class Building { final String name; Building({required this.name}); factory Building.fromJson(Map json) { return Building(name: json['name'] ?? ''); } } class AssignedBy { final String id; final String firstName; final String? lastName; AssignedBy({ required this.id, required this.firstName, this.lastName, }); factory AssignedBy.fromJson(Map json) { return AssignedBy( id: json['id']?.toString() ?? '', firstName: json['firstName'] ?? '', lastName: json['lastName'], ); } } class TeamMember { final String id; final String firstName; final String? lastName; TeamMember({ required this.id, required this.firstName, this.lastName, }); factory TeamMember.fromJson(Map json) { return TeamMember( id: json['id']?.toString() ?? '', firstName: json['firstName']?.toString() ?? '', lastName: json['lastName']?.toString(), ); } } class Comment { final String comment; final TeamMember commentedBy; final DateTime timestamp; final List preSignedUrls; Comment({ required this.comment, required this.commentedBy, required this.timestamp, required this.preSignedUrls, }); factory Comment.fromJson(Map json) { return Comment( comment: json['comment']?.toString() ?? '', commentedBy: json['employee'] != null ? TeamMember.fromJson(json['employee']) : TeamMember(id: '', firstName: '', lastName: null), timestamp: DateTime.parse(json['commentDate'] ?? ''), preSignedUrls: (json['preSignedUrls'] as List?) ?.map((e) => e.toString()) .toList() ?? [], ); } }