// lib/models/property_asset.dart import 'dart:convert'; /// Top-level convenience List propertyAssetFromJson(String str) => (json.decode(str) as List) .map((e) => PropertyAsset.fromJson(e as Map)) .toList(); String propertyAssetToJson(List list) => json.encode(list.map((e) => e.toJson()).toList()); class PropertyAsset { PropertyAsset({ required this.id, required this.assetName, required this.description, this.detailModel, this.detailDescription, this.inGuarantee, this.guaranteeEndDate, this.reference, this.quantity, required this.timestamp, }); final int id; final AssetName assetName; final String description; final String? detailModel; final String? detailDescription; final bool? inGuarantee; final int? guaranteeEndDate; // or DateTime if you prefer conversion final String? reference; final int? quantity; final int timestamp; factory PropertyAsset.fromJson(Map json) => PropertyAsset( id: json['id'] as int, assetName: AssetName.fromJson(json['assetName'] as Map), description: json['description'] as String? ?? '', detailModel: json['detailModel'] as String?, detailDescription: json['detailDescription'] as String?, inGuarantee: json['inGuarantee'] as bool?, guaranteeEndDate: json['guaranteeEndDate'] as int?, reference: json['reference'] as String?, quantity: json['quantity'] as int?, timestamp: json['timestamp'] as int, ); Map toJson() => { 'id': id, 'assetName': assetName.toJson(), 'description': description, 'detailModel': detailModel, 'detailDescription': detailDescription, 'inGuarantee': inGuarantee, 'guaranteeEndDate': guaranteeEndDate, 'reference': reference, 'quantity': quantity, 'timestamp': timestamp, }; } class AssetName { AssetName({ required this.id, required this.name, required this.nameAr, required this.details, required this.timestamp, }); final int id; final String name; final String nameAr; final List details; final int timestamp; factory AssetName.fromJson(Map json) => AssetName( id: json['id'] as int, name: json['name'] as String? ?? '', nameAr: json['nameAr'] as String? ?? '', details: json['details'] as List? ?? [], timestamp: json['timestamp'] as int, ); Map toJson() => { 'id': id, 'name': name, 'nameAr': nameAr, 'details': details, 'timestamp': timestamp, }; }