import 'dart:developer'; import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/models/lookup.dart'; class GenericAttachmentModel { GenericAttachmentModel({ this.id, this.name, this.module, this.subModule, this.uploadedBy, this.originalName, this.createdBy, this.documentType, this.attachmentDescription, this.attachmentURL, this.moduleReferenceId, this.attachmentTypeId, this.createdDate, this.modifiedBy, this.modifiedDate, this.supplierId, }); int? id; String? name; String ? module; String ? subModule; String ? uploadedBy; String? createdBy; String? originalName; Lookup? documentType; String? attachmentDescription; String? attachmentURL; num? moduleReferenceId; num? attachmentTypeId; String? createdDate; String? modifiedBy; String? modifiedDate; num? supplierId; GenericAttachmentModel.fromJson(Map json, {bool convertToLink = false}) { id = json['id']; name = json['name'] ?? json['attachmentName'] ?? json['imageName']; createdBy = json['createdBy']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; originalName = json['originalName'] ?? json['imageOriginalName']; if (convertToLink) { name = URLs.getFileUrl(name); } } GenericAttachmentModel.fromAssetDocumentJson(Map json, {bool convertToLink = false}) { id = json['id']; name = json['attachmentName'] ?? json['name'] ?? json['imageName']; module = json['module']; subModule = json['subModule']; createdBy = json['createdBy']; createdDate = json['createdDate']; uploadedBy = json['uploadedBy']; originalName = json['originalName'] ?? json['imageOriginalName']; documentType = json['attachmentType'] != null ? Lookup(name: json['attachmentType'], id: 0) : null; if (convertToLink && name != null) { name = URLs.getFileUrl(name); } } GenericAttachmentModel.fromWorkOrderJson(Map json) { id = json['id']; name = json['name']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; createdBy = json['createdBy']; } GenericAttachmentModel.fromLoanJson(Map json) { id = json['id']?.toInt(); name = json['attachmentName']; attachmentDescription = json['attachmentDescription']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; moduleReferenceId = json['loanId']; attachmentTypeId = json['loanAttachmentTypeId']; } GenericAttachmentModel.fromLoanDetailJson(Map json) { id = json['id']; name = json['attachmentName']; attachmentDescription = json['attachmentDescription']; moduleReferenceId = json['loanId']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; attachmentTypeId = json['loanAttachmentTypeId']; createdBy = json['createdBy']; createdDate = json['createdDate']; modifiedBy = json['modifiedBy']; modifiedDate = json['modifiedDate']; } GenericAttachmentModel.fromPpmJson(Map json) { id = json['id']; name = json['attachmentName'] ?? json['name']; moduleReferenceId = json['visitId']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; attachmentURL = json['attachmentURL']; } GenericAttachmentModel.fromSupplierJson(Map json) { id = json['id']; name = json['attachmentName'] ?? json['name']; supplierId = json['supplierId']; moduleReferenceId = json['visitId']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; attachmentURL = json['attachmentURL']; } GenericAttachmentModel.fromGasRefillJson(Map json) { id = json['id']; name = json['attachmentName']; moduleReferenceId = json['gasRefillId']; documentType = json['documentType'] != null ? Lookup.fromJson(json['documentType']) : null; } GenericAttachmentModel.fromIncidentJson(Map json) { id = json['id']; name = json['attachmentName']; moduleReferenceId = json['incidentId']; attachmentDescription = json['attachmentDescription']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; } GenericAttachmentModel.fromAssetTransferJson(Map json) { id = json['id']; name = json['attachmentName']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; } GenericAttachmentModel.fromDemoJson(Map json) { id = json['id']; name = json['attachmentName']; originalName = json['originalName']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; moduleReferenceId = json['demoRequestId']; } GenericAttachmentModel.fromInternalAuditJson(Map json) { id = json['id']; name = (json['name'] != null && !json['name'].toString().startsWith('data:image/jpeg')) ? json['name'] : null; originalName = json['originalName']; createdBy = json['createdBy']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; } GenericAttachmentModel.fromPreventiveVisitJson(Map json) { id = json['id']; name = json['attachmentName']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; } GenericAttachmentModel.fromAssetJson(Map json) { id = json['id']; name = json['attachmentName']; attachmentURL = json['attachmentURL']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; originalName = json['originalName']; } GenericAttachmentModel.fromAssetInventoryJson(Map json) { id = json['id']; name = json['attachmentName']; attachmentURL = json['attachmentURL']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; originalName = json['originalName']; } GenericAttachmentModel.fromTrafJson(Map json) { id = json['id']; moduleReferenceId= json['trafId']; name = json['attachmentName']; attachmentDescription = json['attachmentDescription']; moduleReferenceId = json['trafId']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; } Map toJson() { final Map data = {}; data['id'] = id; data['name'] = name; data['createdBy'] = createdBy; data['originalName'] = originalName; data['documentTypeId'] = documentType?.id; return data; } Map toWorkOrderJson() { final Map data = {}; data['id'] = id; data['name'] = name; data['createdBy'] = createdBy; ///TODO need to keep same variable for document type in backend for all modules, currently it is different for different modules if (documentType != null) { data['attachmentTypeId'] = documentType?.id; } return data; } Map toLoanJson() { final Map data = {}; data['id'] = id; data['attachmentName'] = name; data['loanId'] = moduleReferenceId; data['loanAttachmentTypeId'] = documentType?.id; // data['documentTypeId'] = documentType?.id; data['attachmentDescription'] = attachmentDescription; return data; } Map toLoanDetailJson() { final Map data = {}; data['id'] = id; data['attachmentName'] = name; data['loanId'] = moduleReferenceId; data['loanAttachmentTypeId'] = attachmentTypeId; data['attachmentDescription'] = attachmentDescription; data['createdBy'] = createdBy; data['createdDate'] = createdDate; data['documentTypeId'] = documentType?.id; data['modifiedBy'] = modifiedBy; data['modifiedDate'] = modifiedDate; return data; } Map toGasRefillJson() { final Map data = {}; data['id'] = id; data['gasRefillId'] = moduleReferenceId; data['attachmentName'] = name; data['documentTypeId'] = documentType?.id; return data; } Map toIncidentJson() { final Map data = {}; data['id'] = id; data['attachmentName'] = name; data['incidentId'] = moduleReferenceId; data['attachmentTypeId'] = documentType?.id; data['attachmentDescription'] = attachmentDescription; return data; } Map toAssetTransferJson() { final Map data = {}; data['id'] = id; data['attachmentName'] = name; data['attachmentTypeId'] = documentType?.id; return data; } Map toDemoJson() { final Map data = {}; data['id'] = id; data['attachmentName'] = name; data['demoRequestId'] = moduleReferenceId; data['originalName'] = originalName; if (documentType != null) { data['documentTypeId'] = documentType?.id; } return data; } Map toInternalAuditJson() { final Map data = {}; data['id'] = id; data['name'] = name; data['originalName'] = originalName; data['attachmentTypeId'] = documentType?.id; return data; } Map toPreventiveVisitJson() { final Map data = {}; data['id'] = id; data['attachmentName'] = name; data['attachmentTypeId'] = documentType?.id; return data; } Map toAssetJson() { final Map data = {}; data['id'] = id; data['attachmentName'] = name; data['attachmentURL'] = attachmentURL; data['documentTypeId'] = documentType?.id; data['originalName'] = originalName; return data; } Map toAssetDeliveryJson() { final Map data = {}; data['id'] = id; data['name'] = name; data['attachmentTypeId'] = documentType?.id; data['originalName'] = originalName; data['createdBy'] = createdBy; return data; } Map toInventoryJson() { final Map data = {}; data['id'] = id; data['Name'] = name; data['attachmentURL'] = attachmentURL; data['attachmentTypeId'] = documentType?.id; data['originalName'] = originalName; return data; } Map toTrafJson() { final Map data = {}; data['id'] = id; data['trafId'] = moduleReferenceId; data['attachmentName'] = name; data['attachmentTypeId'] = documentType?.id; return data; } Map toSupplierJson() { final Map data = {}; data['id'] = id; data['supplierId'] = supplierId; data['documentTypeId'] = documentType?.id; data['attachmentName'] = name; data['attachmentURL'] = attachmentURL; return data; } Map toTaskJson() { final Map data = {}; data['id'] = id; data['name'] = name; data['createdBy'] = createdBy; data['originalName'] = originalName; data['attachmentTypeId'] = documentType?.id; return data; } }