// ignore_for_file: public_member_api_docs, sort_constructors_first import 'dart:convert'; import 'dart:ui'; import 'package:enum_to_string/enum_to_string.dart'; import 'package:rrispat_app/src/features/ticket/ticket_enums.dart'; class TicketModel { String id; String createdBy; String userDepartment; String assignTo; String againstDepartment; String hod; String subDepartment; String teamLead; int timeDuration; String description; DateTime? createdAt; TicketStatus status; int userRating; UserReviewStatus userReviewStatus; String rejectionRemark; String reviewRemark; List<String> solutionRemarks = []; DateTime? assigningTime; DateTime? estimatedTime; TicketModel({ this.id = '', this.createdBy = '', this.userDepartment = '', this.assignTo = '', this.againstDepartment = '', this.hod = '', this.subDepartment = '', this.teamLead = '', this.timeDuration = 0, this.description = '', this.userRating = 0, this.rejectionRemark = '', this.reviewRemark = '', this.solutionRemarks = const [], this.userReviewStatus = UserReviewStatus.reviewNotReceived, this.createdAt, this.assigningTime, this.estimatedTime, this.status = TicketStatus.created, // required this.status, }); TicketModel copyWith({ String? id, String? createdBy, String? userDepartment, String? assignTo, String? againstDepartment, String? hod, String? subDepartment, String? teamLead, int? timeDuration, String? description, int? userRating, UserReviewStatus? userReviewStatus, String? rejectionRemark, String? reviewRemark, List<String>? solutionRemarks, DateTime? createdAt, TicketStatus? status, }) { return TicketModel( id: id ?? this.id, createdBy: createdBy ?? this.createdBy, userDepartment: userDepartment ?? this.userDepartment, assignTo: assignTo ?? this.assignTo, againstDepartment: againstDepartment ?? this.againstDepartment, hod: hod ?? this.hod, subDepartment: subDepartment ?? this.subDepartment, teamLead: teamLead ?? this.teamLead, timeDuration: timeDuration ?? this.timeDuration, description: description ?? this.description, userRating: userRating ?? this.userRating, userReviewStatus: userReviewStatus ?? this.userReviewStatus, rejectionRemark: rejectionRemark ?? this.rejectionRemark, reviewRemark: reviewRemark ?? this.reviewRemark, solutionRemarks: solutionRemarks ?? this.solutionRemarks, createdAt: createdAt ?? this.createdAt, status: status ?? this.status, ); } Map<String, dynamic> toMap() { return <String, dynamic>{ 'id': id, 'createdBy': createdBy, 'userDepartment': userDepartment, 'assignTo': assignTo, 'againstDepartment': againstDepartment, 'hod': hod, 'subDepartment': subDepartment, 'teamLead': teamLead, 'timeDuration': timeDuration, 'description': description, 'userRating': userRating, 'userReviewStatus': userReviewStatus.name, 'rejectionRemark': rejectionRemark, 'reviewRemark': reviewRemark, 'solutionRemarks': solutionRemarks, 'createdAt': createdAt?.millisecondsSinceEpoch, 'status': status.name, }; } factory TicketModel.fromMap(Map<String, dynamic> map) { return TicketModel( id: map['_id'] as String, createdBy: (map['createdBy'] ?? '') as String, userDepartment: (map['userDepartment'] ?? '') as String, assignTo: (map['assignTo'] ?? '') as String, againstDepartment: (map['againstDepartment'] ?? '') as String, hod: (map['hod'] ?? '') as String, subDepartment: (map['subDepartment'] ?? '') as String, teamLead: (map['teamLead'] ?? '') as String, timeDuration: (map['timeDuration'] ?? 0) as int, description: (map['description'] ?? '') as String, userRating: (map['userRating'] ?? 0) as int, rejectionRemark: (map['rejectionRemark'] ?? '') as String, reviewRemark: (map['reviewRemark'] ?? '') as String, solutionRemarks: List<String>.from(map['solutionRemarks'] ?? []), createdAt: DateTime.parse((map['createdAt'])), status: EnumToString.fromString(TicketStatus.values, map['status'].toString()) as TicketStatus, userReviewStatus: EnumToString.fromString( UserReviewStatus.values, map['userReviewStatus'].toString()) as UserReviewStatus, ); } String toJson() => json.encode(toMap()); factory TicketModel.fromJson(String source) => TicketModel.fromMap(json.decode(source) as Map<String, dynamic>); @override String toString() { return 'TicketModel(id: $id, createdBy: $createdBy, userDepartment: $userDepartment, assignTo: $assignTo, againstDepartment: $againstDepartment, hod: $hod, subDepartment: $subDepartment, teamLead: $teamLead, timeDuration: $timeDuration, description: $description,userRating: $userRating,userReviewStatus: $userReviewStatus, rejectionRemark: $rejectionRemark,reviewRemark: $reviewRemark,solutionRemarks: $solutionRemarks, createdAt: $createdAt, status: $status)'; } @override bool operator ==(covariant TicketModel other) { if (identical(this, other)) return true; return other.id == id && other.createdBy == createdBy && other.userDepartment == userDepartment && other.assignTo == assignTo && other.againstDepartment == againstDepartment && other.hod == hod && other.subDepartment == subDepartment && other.teamLead == teamLead && other.timeDuration == timeDuration && other.description == description && other.userRating == userRating && other.userReviewStatus == userReviewStatus && other.rejectionRemark == rejectionRemark && other.reviewRemark == reviewRemark && other.solutionRemarks == solutionRemarks && other.createdAt == createdAt && other.status == status; } @override int get hashCode { return hashList([ id, createdBy, userDepartment, assignTo, againstDepartment, hod, subDepartment, teamLead, timeDuration, description, userRating, userReviewStatus, rejectionRemark, reviewRemark, solutionRemarks, createdAt, status, ]); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter