import 'package:test_sa/models/device/supplier.dart';

class ModelDefinition {
  ModelDefinition({
    this.id,
    this.assetName,
    this.assetDescription,
    this.modelDefCode,
    this.modelName,
    this.manufacturerId,
    this.manufacturerName,
    this.supplierName,
    this.replacementDate,
    this.essentialEquipement,
    this.businessCritical,
    this.lifeSpan,
    this.modelDefRelatedDefects,
    this.suppliers,
  });

  ModelDefinition.fromJson(dynamic json) {
    id = json['id'];
    assetName = json['assetName'];
    assetDescription = json['assetDescription'];
    modelDefCode = json['modelDefCode'];
    modelName = json['modelName'];
    manufacturerId = json['manufacturerId'];
    manufacturerName = json['manufacturerName'];
    supplierName = json['supplierName'];
    replacementDate = json['replacementDate'];
    essentialEquipement = json['essentialEquipement'];
    businessCritical = json['businessCritical'];
    lifeSpan = json['lifeSpan'];
    if (json['modelDefRelatedDefects'] != null) {
      modelDefRelatedDefects = [];
      json['modelDefRelatedDefects'].forEach((v) {
        modelDefRelatedDefects.add(ModelDefRelatedDefects.fromJson(v));
      });
    }
    if (json['suppliers'] != null) {
      suppliers = [];
      json['suppliers'].forEach((v) {
        suppliers.add(Supplier.fromJson(v));
      });
    }
  }

  num id;
  String assetName;
  String assetDescription;
  String modelDefCode;
  String modelName;
  num manufacturerId;
  String manufacturerName;
  dynamic supplierName;
  String replacementDate;
  String essentialEquipement;
  String businessCritical;
  num lifeSpan;
  List<ModelDefRelatedDefects> modelDefRelatedDefects;
  List<Supplier> suppliers;

  ModelDefinition copyWith({
    num id,
    String assetName,
    String assetDescription,
    String modelDefCode,
    String modelName,
    num manufacturerId,
    String manufacturerName,
    dynamic supplierName,
    String replacementDate,
    String essentialEquipement,
    String businessCritical,
    num lifeSpan,
    List<ModelDefRelatedDefects> modelDefRelatedDefects,
    List<Supplier> suppliers,
  }) =>
      ModelDefinition(
        id: id ?? this.id,
        assetName: assetName ?? this.assetName,
        assetDescription: assetDescription ?? this.assetDescription,
        modelDefCode: modelDefCode ?? this.modelDefCode,
        modelName: modelName ?? this.modelName,
        manufacturerId: manufacturerId ?? this.manufacturerId,
        manufacturerName: manufacturerName ?? this.manufacturerName,
        supplierName: supplierName ?? this.supplierName,
        replacementDate: replacementDate ?? this.replacementDate,
        essentialEquipement: essentialEquipement ?? this.essentialEquipement,
        businessCritical: businessCritical ?? this.businessCritical,
        lifeSpan: lifeSpan ?? this.lifeSpan,
        modelDefRelatedDefects: modelDefRelatedDefects ?? this.modelDefRelatedDefects,
        suppliers: suppliers ?? this.suppliers,
      );

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['id'] = id;
    map['assetName'] = assetName;
    map['assetDescription'] = assetDescription;
    map['modelDefCode'] = modelDefCode;
    map['modelName'] = modelName;
    map['manufacturerId'] = manufacturerId;
    map['manufacturerName'] = manufacturerName;
    map['supplierName'] = supplierName;
    map['replacementDate'] = replacementDate;
    map['essentialEquipement'] = essentialEquipement;
    map['businessCritical'] = businessCritical;
    map['lifeSpan'] = lifeSpan;
    if (modelDefRelatedDefects != null) {
      map['modelDefRelatedDefects'] = modelDefRelatedDefects.map((v) => v.toJson()).toList();
    }
    if (suppliers != null) {
      map['suppliers'] = suppliers.map((v) => v.toJson()).toList();
    }
    return map;
  }
}

class ModelDefRelatedDefects {
  ModelDefRelatedDefects({
    this.id,
    this.defectName,
    this.workPerformed,
    this.estimatedTime,
  });

  ModelDefRelatedDefects.fromJson(dynamic json) {
    id = json['id'];
    defectName = json['defectName'];
    workPerformed = json['workPerformed'];
    estimatedTime = json['estimatedTime'];
  }

  num id;
  String defectName;
  String workPerformed;
  String estimatedTime;

  ModelDefRelatedDefects copyWith({
    num id,
    String defectName,
    String workPerformed,
    String estimatedTime,
  }) =>
      ModelDefRelatedDefects(
        id: id ?? this.id,
        defectName: defectName ?? this.defectName,
        workPerformed: workPerformed ?? this.workPerformed,
        estimatedTime: estimatedTime ?? this.estimatedTime,
      );

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['id'] = id;
    map['defectName'] = defectName;
    map['workPerformed'] = workPerformed;
    map['estimatedTime'] = estimatedTime;
    return map;
  }
}
