content: // ignore_for_file: public_member_api_docs, sort_constructors_first
  import 'dart:convert';
  
  class CatalogModel {
    static List<Item> items = [
      Item(
          id: 1,
          name: "Iphone 12 Pro",
          desc: "Apple Iphone 12th generation",
          price: 999,
          color: "#33505a",
          image:
              "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRISJ6msIu4AU9_M9ZnJVQVFmfuhfyJjEtbUm3ZK11_8IV9TV25-1uM5wHjiFNwKy99w0mR5Hk&usqp=CAc")
    ];
    // Get item by id
    Item getById(int id) =>
        items.firstWhere((element) => element.id == id, orElse: null);
  
    // Get Item by position
    Item getByPosition(int pos) => items[pos];
  }
  
  class Item {
    late final int id;
    final String name;
    final String desc;
    final num price;
    final String color;
    final String image;
  
    Item({
      required this.id,
      required this.name,
      required this.desc,
      required this.price,
      required this.color,
      required this.image,
    });
  
    Item copyWith({
      int? id,
      String? name,
      String? desc,
      num? price,
      String? color,
      String? image,
    }) {
      return Item(
        id: id ?? this.id,
        name: name ?? this.name,
        desc: desc ?? this.desc,
        price: price ?? this.price,
        color: color ?? this.color,
        image: image ?? this.image,
      );
    }
  
    Map<String, dynamic> toMap() {
      return <String, dynamic>{
        'id': id,
        'name': name,
        'desc': desc,
        'price': price,
        'color': color,
        'image': image,
      };
    }
  
    factory Item.fromMap(Map<String, dynamic> map) {
      return Item(
        id: map['id'] as int,
        name: map['name'] as String,
        desc: map['desc'] as String,
        price: map['price'] as num,
        color: map['color'] as String,
        image: map['image'] as String,
      );
    }
  
    String toJson() => json.encode(toMap());
  
    factory Item.fromJson(String source) =>
        Item.fromMap(json.decode(source) as Map<String, dynamic>);
  
    @override
    String toString() {
      return 'Item(id: $id, name: $name, desc: $desc, price: $price, color: $color, image: $image)';
    }
  
    @override
    bool operator ==(covariant Item other) {
      if (identical(this, other)) return true;
  
      return other.id == id &&
          other.name == name &&
          other.desc == desc &&
          other.price == price &&
          other.color == color &&
          other.image == image;
    }
  
    @override
    int get hashCode {
      return id.hashCode ^
          name.hashCode ^
          desc.hashCode ^
          price.hashCode ^
          color.hashCode ^
          image.hashCode;
    }
  }
  