class TaskModel { final DateTime assignmentDate; final DateTime? reportedDate; final String id; final WorkItem? workItem; final String workItemId; final int plannedTask; final int completedTask; final AssignedBy assignedBy; final List teamMembers; final List comments; TaskModel({ required this.assignmentDate, this.reportedDate, required this.id, required this.workItem, required this.workItemId, required this.plannedTask, required this.completedTask, required this.assignedBy, required this.teamMembers, required this.comments, }); 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'], completedTask: json['completedTask'], assignedBy: AssignedBy.fromJson(json['assignedBy']), teamMembers: (json['teamMembers'] as List) .map((e) => TeamMember.fromJson(e)) .toList(), comments: (json['comments'] as List).map((e) => Comment.fromJson(e)).toList(), ); } } class WorkItem { final String? id; final ActivityMaster? activityMaster; final WorkArea? workArea; final int? plannedWork; final int? completedWork; WorkItem({ this.id, this.activityMaster, this.workArea, this.plannedWork, this.completedWork, }); 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'], completedWork: json['completedWork'], ); } } class ActivityMaster { final String activityName; ActivityMaster({required this.activityName}); factory ActivityMaster.fromJson(Map json) { return ActivityMaster(activityName: json['activityName'] ?? ''); } } class WorkArea { final String areaName; final Floor? floor; WorkArea({required this.areaName, this.floor}); factory WorkArea.fromJson(Map json) { return WorkArea( 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; Comment({ required this.comment, required this.commentedBy, required this.timestamp, }); 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'] ?? ''), ); } }