import 'package:worker_client/models/entities/ExtendContent.dart';
import 'package:worker_client/models/entities/MachineryImage.dart';

class Machinery {
  // APP 注册状态
  String? appStatus;
  //购买时间
  String? buyDate;
//  创建时间
  String? createDate;
//  创建用户
  String? createUser;
//  押金
  int? deposit;
//  工作状态
  String? jobStatus;
//  人工费
  int? laborCost;
//  当前位置
  String? location;
//  农机Id
  String? machineryId;
//  名称
  String? name;
//  机构ID
  String? orgId;
//  机构名称
  String? orgName;
//  农机价格
  int? price;
  //  归属区域id
  String? regionId;
  //  归属区域名
  String? regionName;
  //  状态
  int? status;
  //  主图
  String? thumb;
  //  农机类型
  String? typeId;
  //  类型名称
  String? typeName;
  //  更新时间
  String? updateDate;
  //  更新用户
  String? updateUser;

  //农机详情列表
  List<ExtendContent>? contentList = [];

  //农机banner图集
  List<MachineryImage>? imagesList = [];

  Machinery();

  Machinery.fromJson(Map<String, dynamic> json)
      : machineryId = json["machineryId"],
        name = json["name"],
        typeId = json["typeId"],
        typeName = json["typeName"],
        price = json["price"],
        thumb = json["thumb"],
        location = json["location"],
        // distance=json["distance"],调度？？
        orgId = json["orgId"],
        orgName = json["orgName"],
        jobStatus = json["jobStatus"],
        status = json["status"],
        contentList = jsonToContentList(json["contentList"]),
        imagesList = jsonToImagesList(json["imagesList"]);

  Map<String, dynamic> toJson() => {
        'machineryId': machineryId,
        'name': name,
        'typeId': typeId,
        'typeName': typeName,
        'price': price,
        'thumb': thumb,
        'location': location,
        // 'distance':distance,
        'orgId': orgId,
        'orgName': orgName,
        'jobStatus': jobStatus,
        'status': status,
        'contentList': ListTojson(contentList),
        'imagesList': ListTojson(imagesList),
      };
}

List<ExtendContent> jsonToContentList(list) {
  List<ExtendContent> contList = [];
  if (list!=null) {
    list.forEach((item) {
      contList.add(ExtendContent.fromJson(item));
    });
  }
  return contList;
}

List<MachineryImage> jsonToImagesList(list) {
  List<MachineryImage> contList = [];
  if (list!=null) {
    list.forEach((item) {
      contList.add(MachineryImage.fromJson(item));
    });
  }
  return contList;
}

List<Map<String, dynamic>> ListTojson(list) {
  List<Map<String, dynamic>> contList = [];
  list.forEach((item) {
    contList.add(item.toJson());
  });
  return contList;
}
