import '../base.dart';

class SparePartsWorkOrders extends Base {
  SparePartsWorkOrders({this.id, this.sparePart, this.qty, this.returnQty, this.installQty}) : super(identifier: id?.toString(), name: sparePart?.partName);

  SparePartsWorkOrders.fromJson(dynamic json) {
    id = json['id'];
    sparePart = json['sparePart'] != null ? SparePart.fromJson(json['sparePart'],true) : null;
    qty = json['qty'];

    returnQty = json['returnQty'];
    installQty = json['installQty'];
  }

  num? id;
  SparePart? sparePart;
  num? qty;
  num? returnQty;
  num? installQty;

  SparePartsWorkOrders copyWith({num? id, SparePart? sparePart, num? qty, num? returnQty, num? installQty}) =>
      SparePartsWorkOrders(id: id ?? this.id, sparePart: sparePart ?? this.sparePart, qty: qty ?? this.qty, returnQty: returnQty ?? this.returnQty, installQty: installQty ?? this.installQty);

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['id'] = id;
    if (sparePart != null) {
      map['sparePart'] = sparePart!.toJson();
    }
    map['qty'] = qty ?? 0;
    map['returnQty'] = returnQty;
    map['installQty'] = installQty;
    return map;
  }
}

class SparePart extends Base {
  SparePart({
    this.id,
    this.partNo,
    this.partName,
    this.oracleCode,
    this.displayName,
    this.assetId,
  }) : super(identifier: id?.toString(), name: partName);

  SparePart.fromJson(dynamic json,bool ?isDisplayName) {
    id = json['id'];
    identifier = id?.toString();
    partNo = json['partNo'];
    partName = json['partName'];
    displayName = json['displayName'];
    oracleCode = json['oracleCode'];
    name = isDisplayName!=null&&isDisplayName?displayName: partName;
    assetId = json['assetId'];
  }

  num? id;
  String? partNo;
  String? partName;
  String? displayName;
  String? oracleCode;
  num? assetId;

  SparePart copyWith({num? id, String? partNo, String? partName, num? assetId,String?oracleCode,String ?displayName}) =>
      SparePart(id: id ?? this.id,oracleCode: oracleCode?? this.oracleCode, partNo: partNo ?? this.partNo, partName: partName ?? this.partName, assetId: assetId ?? this.assetId,displayName: displayName??this.displayName);

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['id'] = id;
    map['partNo'] = partNo;
    map['partName'] = partName;
    map['displayName'] = displayName;
    map['oracleCode'] = oracleCode;
    map['assetId'] = assetId;
    return map;
  }
}

class StoreAvailability {
  final int ?id;
  final int? storeId;
  final int ?availablityQty;
  final String? siteName;
  final String ?storeName;
  final int? requestedQty;
  final bool? alreadyRequestFromThisStore;

  StoreAvailability({
     this.id,
     this.storeId,
     this.availablityQty,
     this.siteName,
     this.storeName,
     this.requestedQty,
     this.alreadyRequestFromThisStore,
  });

  factory StoreAvailability.fromJson(Map<String, dynamic> json) {
    return StoreAvailability(
      id: json['id'] ?? 0,
      storeId: json['storeId'] ?? 0,
      availablityQty: json['availablityQty'] ?? 0,
      siteName: json['siteName'] ?? '',
      storeName: json['storeName'] ?? '',
      requestedQty: json['requestedQty'] ?? 0,
      alreadyRequestFromThisStore: json['alreadyRequestFromThisStore'] ?? false,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'storeId': storeId,
      'availablityQty': availablityQty,
      'siteName': siteName,
      'storeName': storeName,
      'requestedQty': requestedQty,
      'alreadyRequestFromThisStore': alreadyRequestFromThisStore,
    };
  }
}

