import 'package:domain/generated/json/base/json_convert_content.dart';
import 'package:domain/entity/garage_sale_history_entity.dart';
import 'package:domain/entity/id_name_entity.dart';


GarageSaleHistoryEntity $GarageSaleHistoryEntityFromJson(Map<String, dynamic> json) {
  final GarageSaleHistoryEntity garageSaleHistoryEntity = GarageSaleHistoryEntity();
  final int? count = jsonConvert.convert<int>(json['count']);
  if (count != null) {
    garageSaleHistoryEntity.count = count;
  }
  final int? page = jsonConvert.convert<int>(json['page']);
  if (page != null) {
    garageSaleHistoryEntity.page = page;
  }
  final int? limit = jsonConvert.convert<int>(json['limit']);
  if (limit != null) {
    garageSaleHistoryEntity.limit = limit;
  }
  final int? countPage = jsonConvert.convert<int>(json['count_page']);
  if (countPage != null) {
    garageSaleHistoryEntity.countPage = countPage;
  }
  final List<GarageSaleHistoryList>? list = (json['list'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<GarageSaleHistoryList>(e) as GarageSaleHistoryList).toList();
  if (list != null) {
    garageSaleHistoryEntity.list = list;
  }
  return garageSaleHistoryEntity;
}

Map<String, dynamic> $GarageSaleHistoryEntityToJson(GarageSaleHistoryEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['count'] = entity.count;
  data['page'] = entity.page;
  data['limit'] = entity.limit;
  data['count_page'] = entity.countPage;
  data['list'] = entity.list.map((v) => v.toJson()).toList();
  return data;
}

extension GarageSaleHistoryEntityExtension on GarageSaleHistoryEntity {
  GarageSaleHistoryEntity copyWith({
    int? count,
    int? page,
    int? limit,
    int? countPage,
    List<GarageSaleHistoryList>? list,
  }) {
    return GarageSaleHistoryEntity()
      ..count = count ?? this.count
      ..page = page ?? this.page
      ..limit = limit ?? this.limit
      ..countPage = countPage ?? this.countPage
      ..list = list ?? this.list;
  }
}

GarageSaleHistoryList $GarageSaleHistoryListFromJson(Map<String, dynamic> json) {
  final GarageSaleHistoryList garageSaleHistoryList = GarageSaleHistoryList();
  final String? id = jsonConvert.convert<String>(json['id']);
  if (id != null) {
    garageSaleHistoryList.id = id;
  }
  final String? sn = jsonConvert.convert<String>(json['sn']);
  if (sn != null) {
    garageSaleHistoryList.sn = sn;
  }
  final String? orderStatus = jsonConvert.convert<String>(json['order_status']);
  if (orderStatus != null) {
    garageSaleHistoryList.orderStatus = orderStatus;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    garageSaleHistoryList.createdAt = createdAt;
  }
  final IdNameEntity? service = jsonConvert.convert<IdNameEntity>(json['service']);
  if (service != null) {
    garageSaleHistoryList.service = service;
  }
  final IdNameEntity? merchant = jsonConvert.convert<IdNameEntity>(json['merchant']);
  if (merchant != null) {
    garageSaleHistoryList.merchant = merchant;
  }
  final List<GarageSaleHistoryListOrderProducts>? orderProducts = (json['order_products'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<GarageSaleHistoryListOrderProducts>(e) as GarageSaleHistoryListOrderProducts).toList();
  if (orderProducts != null) {
    garageSaleHistoryList.orderProducts = orderProducts;
  }
  return garageSaleHistoryList;
}

Map<String, dynamic> $GarageSaleHistoryListToJson(GarageSaleHistoryList entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['sn'] = entity.sn;
  data['order_status'] = entity.orderStatus;
  data['created_at'] = entity.createdAt;
  data['service'] = entity.service?.toJson();
  data['merchant'] = entity.merchant?.toJson();
  data['order_products'] = entity.orderProducts.map((v) => v.toJson()).toList();
  return data;
}

extension GarageSaleHistoryListExtension on GarageSaleHistoryList {
  GarageSaleHistoryList copyWith({
    String? id,
    String? sn,
    String? orderStatus,
    String? createdAt,
    IdNameEntity? service,
    IdNameEntity? merchant,
    List<GarageSaleHistoryListOrderProducts>? orderProducts,
  }) {
    return GarageSaleHistoryList()
      ..id = id ?? this.id
      ..sn = sn ?? this.sn
      ..orderStatus = orderStatus ?? this.orderStatus
      ..createdAt = createdAt ?? this.createdAt
      ..service = service ?? this.service
      ..merchant = merchant ?? this.merchant
      ..orderProducts = orderProducts ?? this.orderProducts;
  }
}

GarageSaleHistoryListOrderProducts $GarageSaleHistoryListOrderProductsFromJson(Map<String, dynamic> json) {
  final GarageSaleHistoryListOrderProducts garageSaleHistoryListOrderProducts = GarageSaleHistoryListOrderProducts();
  final String? id = jsonConvert.convert<String>(json['id']);
  if (id != null) {
    garageSaleHistoryListOrderProducts.id = id;
  }
  final String? productName = jsonConvert.convert<String>(json['product_name']);
  if (productName != null) {
    garageSaleHistoryListOrderProducts.productName = productName;
  }
  final int? quantity = jsonConvert.convert<int>(json['quantity']);
  if (quantity != null) {
    garageSaleHistoryListOrderProducts.quantity = quantity;
  }
  final String? totalAmount = jsonConvert.convert<String>(json['total_amount']);
  if (totalAmount != null) {
    garageSaleHistoryListOrderProducts.totalAmount = totalAmount;
  }
  final String? plannedServiceAt = jsonConvert.convert<String>(json['planned_service_at']);
  if (plannedServiceAt != null) {
    garageSaleHistoryListOrderProducts.plannedServiceAt = plannedServiceAt;
  }
  return garageSaleHistoryListOrderProducts;
}

Map<String, dynamic> $GarageSaleHistoryListOrderProductsToJson(GarageSaleHistoryListOrderProducts entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['product_name'] = entity.productName;
  data['quantity'] = entity.quantity;
  data['total_amount'] = entity.totalAmount;
  data['planned_service_at'] = entity.plannedServiceAt;
  return data;
}

extension GarageSaleHistoryListOrderProductsExtension on GarageSaleHistoryListOrderProducts {
  GarageSaleHistoryListOrderProducts copyWith({
    String? id,
    String? productName,
    int? quantity,
    String? totalAmount,
    String? plannedServiceAt,
  }) {
    return GarageSaleHistoryListOrderProducts()
      ..id = id ?? this.id
      ..productName = productName ?? this.productName
      ..quantity = quantity ?? this.quantity
      ..totalAmount = totalAmount ?? this.totalAmount
      ..plannedServiceAt = plannedServiceAt ?? this.plannedServiceAt;
  }
}