mirrored_repositories/vakinha_app/lib/app
import 'dart:convert';

class ProductModel {
  factory ProductModel.fromJson(String source) =>
      ProductModel.fromMap(json.decode(source));

  factory ProductModel.fromMap(Map<String, dynamic> map) {
    return ProductModel(
      id: map['id'] ?? 0,
      name: map['name'] ?? '',
      description: map['description'] ?? '',
      price: map['price']?.toDouble() ?? 0.0,
      image: map['image'] ?? '',
    );
  }

  ProductModel({
    required this.id,
    required this.name,
    required this.description,
    required this.price,
    required this.image,
  });

  final int id;
  final String name;
  final String description;
  final double price;
  final String image;

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'name': name,
      'description': description,
      'price': price,
      'image': image,
    };
  }

  String toJson() => json.encode(toMap());
}
