// ignore_for_file: public_member_api_docs, sort_constructors_first import 'dart:convert'; class ProductResponseModel { final bool? success; final ProductData? data; final dynamic errors; ProductResponseModel({ this.success, this.data, this.errors, }); factory ProductResponseModel.fromJson(String str) => ProductResponseModel.fromMap(json.decode(str)); String toJson() => json.encode(toMap()); factory ProductResponseModel.fromMap(Map json) => ProductResponseModel( success: json["success"], data: json["data"] == null ? null : ProductData.fromMap(json["data"]), errors: json["errors"], ); Map toMap() => { "success": success, "data": data?.toMap(), "errors": errors, }; } class ProductData { final List? products; final int? totalCount; final int? page; final int? limit; final int? totalPages; ProductData({ this.products, this.totalCount, this.page, this.limit, this.totalPages, }); factory ProductData.fromMap(Map json) => ProductData( products: json["products"] == null ? [] : List.from( json["products"].map((x) => Product.fromMap(x))), totalCount: json["total_count"], page: json["page"], limit: json["limit"], totalPages: json["total_pages"], ); Map toMap() => { "products": products == null ? [] : List.from(products!.map((x) => x.toMap())), "total_count": totalCount, "page": page, "limit": limit, "total_pages": totalPages, }; } class Product { final String? id; final String? organizationId; final String? categoryId; final String? sku; final String? name; final String? description; final int? price; final int? cost; final String? businessType; final String? imageUrl; final String? printerType; final Map? metadata; final bool? isActive; final DateTime? createdAt; final DateTime? updatedAt; final List? variants; Product({ this.id, this.organizationId, this.categoryId, this.sku, this.name, this.description, this.price, this.cost, this.businessType, this.imageUrl, this.printerType, this.metadata, this.isActive, this.createdAt, this.updatedAt, this.variants, }); factory Product.fromJson(String str) => Product.fromMap(json.decode(str)); String toJson() => json.encode(toMap()); factory Product.fromMap(Map json) => Product( id: json["id"], organizationId: json["organization_id"], categoryId: json["category_id"], sku: json["sku"], name: json["name"], description: json["description"], price: json["price"], cost: json["cost"], businessType: json["business_type"], imageUrl: json["image_url"], printerType: json["printer_type"], metadata: json["metadata"] ?? {}, isActive: json["is_active"], createdAt: json["created_at"] == null ? null : DateTime.parse(json["created_at"]), updatedAt: json["updated_at"] == null ? null : DateTime.parse(json["updated_at"]), variants: json["variants"] == null ? [] : List.from( json["variants"].map((x) => ProductVariant.fromMap(x))), ); factory Product.fromOrderMap(Map json) => Product( id: json["id_product"], price: json["price"], ); factory Product.fromLocalMap(Map json) => Product( id: json["id"], organizationId: json["organization_id"], categoryId: json["category_id"], sku: json["sku"], name: json["name"], description: json["description"], price: json["price"], cost: json["cost"], businessType: json["business_type"], imageUrl: json["image_url"], printerType: json["printer_type"], metadata: json["metadata"] ?? {}, isActive: json["is_active"], createdAt: json["created_at"] == null ? null : DateTime.parse(json["created_at"]), updatedAt: json["updated_at"] == null ? null : DateTime.parse(json["updated_at"]), variants: json["variants"] == null ? [] : List.from( json["variants"].map((x) => ProductVariant.fromMap(x))), ); Map toLocalMap() => { "id": id, "organization_id": organizationId, "category_id": categoryId, "sku": sku, "name": name, "description": description, "price": price, "cost": cost, "business_type": businessType, "image_url": imageUrl, "printer_type": printerType, "metadata": metadata, "is_active": isActive, "created_at": createdAt?.toIso8601String(), "updated_at": updatedAt?.toIso8601String(), "variants": variants == null ? [] : List.from(variants!.map((x) => x.toMap())), }; Map toMap() => { "id": id, "organization_id": organizationId, "category_id": categoryId, "sku": sku, "name": name, "description": description, "price": price, "cost": cost, "business_type": businessType, "image_url": imageUrl, "printer_type": printerType, "metadata": metadata, "is_active": isActive, "created_at": createdAt?.toIso8601String(), "updated_at": updatedAt?.toIso8601String(), "variants": variants == null ? [] : List.from(variants!.map((x) => x.toMap())), }; @override bool operator ==(covariant Product other) { if (identical(this, other)) return true; return other.id == id && other.organizationId == organizationId && other.categoryId == categoryId && other.sku == sku && other.name == name && other.description == description && other.price == price && other.cost == cost && other.businessType == businessType && other.imageUrl == imageUrl && other.printerType == printerType && other.metadata == metadata && other.isActive == isActive && other.createdAt == createdAt && other.updatedAt == updatedAt && _listEquals(other.variants, variants); } bool _listEquals(List? a, List? b) { if (a == null && b == null) return true; if (a == null || b == null) return false; if (a.length != b.length) return false; for (int i = 0; i < a.length; i++) { if (a[i] != b[i]) return false; } return true; } @override int get hashCode { return id.hashCode ^ organizationId.hashCode ^ categoryId.hashCode ^ sku.hashCode ^ name.hashCode ^ description.hashCode ^ price.hashCode ^ cost.hashCode ^ businessType.hashCode ^ imageUrl.hashCode ^ printerType.hashCode ^ metadata.hashCode ^ isActive.hashCode ^ createdAt.hashCode ^ updatedAt.hashCode ^ variants.hashCode; } Product copyWith({ String? id, String? organizationId, String? categoryId, String? sku, String? name, String? description, int? price, int? cost, String? businessType, String? imageUrl, String? printerType, Map? metadata, bool? isActive, DateTime? createdAt, DateTime? updatedAt, List? variants, }) { return Product( id: id ?? this.id, organizationId: organizationId ?? this.organizationId, categoryId: categoryId ?? this.categoryId, sku: sku ?? this.sku, name: name ?? this.name, description: description ?? this.description, price: price ?? this.price, cost: cost ?? this.cost, businessType: businessType ?? this.businessType, imageUrl: imageUrl ?? this.imageUrl, printerType: printerType ?? this.printerType, metadata: metadata ?? this.metadata, isActive: isActive ?? this.isActive, createdAt: createdAt ?? this.createdAt, updatedAt: updatedAt ?? this.updatedAt, variants: variants ?? this.variants, ); } } class Category { final int? id; final String? name; final String? description; final String? image; final DateTime? createdAt; final DateTime? updatedAt; Category({ this.id, this.name, this.description, this.image, this.createdAt, this.updatedAt, }); factory Category.fromJson(String str) => Category.fromMap(json.decode(str)); String toJson() => json.encode(toMap()); factory Category.fromMap(Map json) => Category( id: json["id"] is String ? int.tryParse(json["id"]) : json["id"], name: json["name"], description: json["description"], image: json["image"], createdAt: json["created_at"] == null ? null : DateTime.parse(json["created_at"]), updatedAt: json["updated_at"] == null ? null : DateTime.parse(json["updated_at"]), ); Map toMap() => { "id": id, "name": name, "description": description, "image": image, "created_at": createdAt?.toIso8601String(), "updated_at": updatedAt?.toIso8601String(), }; @override bool operator ==(covariant Category other) { if (identical(this, other)) return true; return other.id == id && other.name == name && other.description == description && other.image == image && other.createdAt == createdAt && other.updatedAt == updatedAt; } @override int get hashCode { return id.hashCode ^ name.hashCode ^ description.hashCode ^ image.hashCode ^ createdAt.hashCode ^ updatedAt.hashCode; } } class ProductVariant { final String? id; final String? productId; final String? name; final int? priceModifier; final int? cost; final Map? metadata; final DateTime? createdAt; final DateTime? updatedAt; ProductVariant({ this.id, this.productId, this.name, this.priceModifier, this.cost, this.metadata, this.createdAt, this.updatedAt, }); factory ProductVariant.fromMap(Map json) => ProductVariant( id: json["id"], productId: json["product_id"], name: json["name"], priceModifier: json["price_modifier"], cost: json["cost"], metadata: json["metadata"] ?? {}, createdAt: json["created_at"] == null ? null : DateTime.parse(json["created_at"]), updatedAt: json["updated_at"] == null ? null : DateTime.parse(json["updated_at"]), ); Map toMap() => { "id": id, "product_id": productId, "name": name, "price_modifier": priceModifier, "cost": cost, "metadata": metadata, "created_at": createdAt?.toIso8601String(), "updated_at": updatedAt?.toIso8601String(), }; }