class Product { final int? id; final int? userId; final int? categoryId; final int? uomId; final String? hsnCode; final String name; final String? sku; final String? barcode; final String? description; final double? purchasePrice; final double? sellingPrice; final double? minStock; final double? reorderLevel; final double? gstRate; final String? dimensions; final double? weight; final String? color; final String? size; final String priceCalcRule; final bool autoCalculatePrice; final double? purityFactor; final double? makingCharges; final String? makingChargesType; final double? wastagePercentage; final bool trackInventory; final bool isActive; final List imageIds; final double? currentStock; Product({ this.id, this.userId, this.categoryId, this.uomId, required this.name, this.hsnCode, this.sku, this.barcode, this.description, this.purchasePrice, this.sellingPrice, this.minStock, this.reorderLevel, this.gstRate, this.dimensions, this.weight, this.color, this.size, this.priceCalcRule = 'MANUAL', this.autoCalculatePrice = false, this.purityFactor = 1.0, this.makingCharges = 0.0, this.makingChargesType = 'FLAT', this.wastagePercentage = 0.0, this.trackInventory = true, this.isActive = true, this.imageIds = const [], this.currentStock = 0.0, }); factory Product.fromJson(Map json) { return Product( id: json['id'], userId: json['userId'] ?? json['user_id'], categoryId: json['categoryId'] ?? json['category_id'], uomId: json['uomId'] ?? json['uom_id'], name: json['name'], hsnCode: json['hsnCode'] ?? json['hsn_code'], sku: json['sku'], barcode: json['barcode'], description: json['description'], purchasePrice: (json['purchasePrice'] ?? json['purchase_price'] as num?)?.toDouble(), sellingPrice: (json['sellingPrice'] ?? json['selling_price'] as num?)?.toDouble(), minStock: (json['minStock'] ?? json['min_stock'] as num?)?.toDouble(), reorderLevel: (json['reorderLevel'] ?? json['reorder_level'] as num?)?.toDouble(), gstRate: (json['gstRate'] ?? json['gst_rate'] as num?)?.toDouble(), dimensions: json['dimensions'], weight: (json['weight'] as num?)?.toDouble(), color: json['color'], size: json['size'], priceCalcRule: json['priceCalcRule'] ?? json['price_calc_rule'] ?? 'MANUAL', autoCalculatePrice: json['autoCalculatePrice'] ?? json['auto_calculate_price'] ?? false, purityFactor: (json['purityFactor'] ?? json['purity_factor'] as num?)?.toDouble() ?? 1.0, makingCharges: (json['makingCharges'] ?? json['making_charges'] as num?)?.toDouble() ?? 0.0, makingChargesType: json['makingChargesType'] ?? json['making_charges_type'] ?? 'FLAT', wastagePercentage: (json['wastagePercentage'] ?? json['wastage_percentage'] as num?)?.toDouble() ?? 0.0, trackInventory: json['trackInventory'] ?? json['track_inventory'] ?? true, isActive: json['isActive'] ?? json['is_active'] ?? true, imageIds: json['images'] != null ? (json['images'] as List).map((i) => i['id'] as int).toList() : [], currentStock: (json['currentStock'] ?? json['current_stock'] as num?)?.toDouble() ?? 0.0, ); } Map toJson() { return { 'id': id, 'userId': userId, 'categoryId': categoryId, 'uomId': uomId, 'name': name, 'hsnCode': hsnCode, 'sku': sku, 'barcode': barcode, 'description': description, 'purchasePrice': purchasePrice, 'sellingPrice': sellingPrice, 'minStock': minStock, 'reorderLevel': reorderLevel, 'gstRate': gstRate, 'dimensions': dimensions, 'weight': weight, 'color': color, 'size': size, 'priceCalcRule': priceCalcRule, 'autoCalculatePrice': autoCalculatePrice, 'purityFactor': purityFactor, 'makingCharges': makingCharges, 'makingChargesType': makingChargesType, 'wastagePercentage': wastagePercentage, 'trackInventory': trackInventory, 'isActive': isActive, }; } }