// lib/domain/entities/discount_entity.dart class DiscountEntity { final String id; final String name; final String shopName; final List images; final String type; final String description; final double price; final double nPrice; final DateTime? startDate; final DateTime? endDate; DiscountEntity({ required this.id, required this.name, required this.shopName, required this.images, required this.type, required this.description, required this.price, required this.nPrice, this.startDate, required this.endDate, }); factory DiscountEntity.fromJson(Map json) { List _parseImages(dynamic imageList) { if (imageList is List) { return imageList.map((img) => (img['Url'] ?? '') as String).toList(); } return []; } return DiscountEntity( // --- FIX IS HERE: Reading "ID" instead of "_id" --- id: json['ID'] ?? '', // Changed from '_id' to 'ID' name: json['Name'] ?? 'بدون نام', shopName: (json['Shop'] != null ? json['Shop']['Name'] : 'فروشگاه') ?? 'فروشگاه', images: _parseImages(json['Images']), type: (json['Type'] != null ? json['Type']['Description'] : 'عمومی') ?? 'عمومی', description: json['Description'] ?? '', price: (json['Price'] as num? ?? 0).toDouble(), nPrice: (json['NPrice'] as num? ?? 0).toDouble(), startDate: json['StartDate'] != null ? DateTime.tryParse(json['StartDate']) : null, endDate: json['EndDate'] != null ? DateTime.tryParse(json['EndDate']) : null, ); } }