import 'dart:convert';

class GymItem {
  final String id;
  final String externalId;
  final String title;
  final String description;
  final int count;
  final double price;
  final String categoryId;
  final List<GymImage> images;
  int localCount = 0;

  GymItem({
    required this.id,
    required this.externalId,
    required this.title,
    required this.description,
    required this.count,
    required this.price,
    required this.categoryId,
    required this.images,
  });

  factory GymItem.fromRawJson(String str) => GymItem.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory GymItem.fromJson(Map<String, dynamic> json) => GymItem(
        id: json["id"],
        externalId: json["ExternalId"],
        title: json["title"],
        description: json["description"],
        count: json["count"],
        price: json["price"] / 100,
        categoryId: json["categoryId"],
        images: List<GymImage>.from(
            json["images"].map((x) => GymImage.fromJson(x))),
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "ExternalId": externalId,
        "title": title,
        "description": description,
        "count": count,
        "price": price * 100,
        "categoryId": categoryId,
        "images": List<dynamic>.from(images.map((x) => x.toJson())),
      };
}

class GymImage {
  final String id;
  final dynamic deletedAt;
  final String url;

  GymImage({
    required this.id,
    required this.deletedAt,
    required this.url,
  });

  factory GymImage.fromRawJson(String str) =>
      GymImage.fromJson(json.decode(str));

  String toRawJson() => json.encode(toJson());

  factory GymImage.fromJson(Map<String, dynamic> json) => GymImage(
        id: json["id"],
        deletedAt: json["deletedAt"],
        url: json["url"],
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "deletedAt": deletedAt,
        "url": url,
      };
}
