class UserModel { final int id; final String name; final String email; final bool isActive; final double score; final Address address; final List<String> tags; final List<Order> orders; const UserModel({ required this.id, required this.name, required this.email, required this.isActive, required this.score, required this.address, required this.tags, required this.orders, }); factory UserModel.fromJson(Map<String, dynamic> json) { return UserModel( id: json['id'] as int, name: json['name'] as String, email: json['email'] as String, isActive: json['isActive'] as bool, score: (json['score'] as num).toDouble(), address: Address.fromJson(json['address'] as Map<String, dynamic>), tags: (json['tags'] as List<dynamic>).map((e) => e as String).toList(), orders: (json['orders'] as List<dynamic>).map((e) => Order.fromJson(e as Map<String, dynamic>)).toList(), ); } Map<String, dynamic> toJson() { return { 'id': id, 'name': name, 'email': email, 'isActive': isActive, 'score': score, 'address': address.toJson(), 'tags': tags, 'orders': orders.map((e) => e.toJson()).toList(), }; } UserModel copyWith({ int? id, String? name, String? email, bool? isActive, double? score, Address? address, List<String>? tags, List<Order>? orders, }) { return UserModel( id: id ?? this.id, name: name ?? this.name, email: email ?? this.email, isActive: isActive ?? this.isActive, score: score ?? this.score, address: address ?? this.address, tags: tags ?? this.tags, orders: orders ?? this.orders, ); } } class Address { final String street; final String city; final String zipCode; const Address({ required this.street, required this.city, required this.zipCode, }); factory Address.fromJson(Map<String, dynamic> json) { return Address( street: json['street'] as String, city: json['city'] as String, zipCode: json['zipCode'] as String, ); } Map<String, dynamic> toJson() { return { 'street': street, 'city': city, 'zipCode': zipCode, }; } Address copyWith({ String? street, String? city, String? zipCode, }) { return Address( street: street ?? this.street, city: city ?? this.city, zipCode: zipCode ?? this.zipCode, ); } } class Order { final int id; final String product; final int quantity; final double price; const Order({ required this.id, required this.product, required this.quantity, required this.price, }); factory Order.fromJson(Map<String, dynamic> json) { return Order( id: json['id'] as int, product: json['product'] as String, quantity: json['quantity'] as int, price: (json['price'] as num).toDouble(), ); } Map<String, dynamic> toJson() { return { 'id': id, 'product': product, 'quantity': quantity, 'price': price, }; } Order copyWith({ int? id, String? product, int? quantity, double? price, }) { return Order( id: id ?? this.id, product: product ?? this.product, quantity: quantity ?? this.quantity, price: price ?? this.price, ); } }