import 'package:test_sa/models/hospital.dart';
import 'package:test_sa/models/lookup.dart';

import 'model.dart';

class Device {
  int id;
  String serialNumber;
  String number;
  String destBuildingName;
  String destDepartmentName;
  String destRoom;
  String destFloor;
  String destSiteName;
  // String brand;
  // String model;
  ModelDefinition modelDefinition;
  Hospital hospital;

  Device({
    this.id,
    this.serialNumber,
    this.number,
    this.hospital,
    this.destBuildingName,
    this.destDepartmentName,
    this.destRoom,
    this.destFloor,
    this.destSiteName,
    // this.brand,
    // this.model,
    this.modelDefinition,
  });

  factory Device.fromJson(Map<String, dynamic> parsedJson) {
    return Device(
        id: parsedJson["id"],
        serialNumber: parsedJson["assetSerialNo"],
        number: parsedJson["assetNumber"],
        modelDefinition: ModelDefinition.fromJson(parsedJson["modelDefinition"]),
        hospital: Hospital.fromJson(parsedJson["site"]),
        destBuildingName: parsedJson["destBuildingName"],
        destDepartmentName: parsedJson["destDepartmentName"],
        destRoom: parsedJson["destRoom"],
        destFloor: parsedJson["destFloor"],
        destSiteName: parsedJson['destSiteName']
        // parsedJson["modelDefinition"] == null ? "" :
        // parsedJson["modelDefinition"]["manufacturerName"],
        // model: parsedJson["modelDefinition"] == null ? "" :
        // parsedJson["modelDefinition"]["modelName"],
        );
  }

  factory Device.fromDevice(Device device) {
    return Device(
      id: device.id,
      serialNumber: device.serialNumber,
      number: device.number,
      // brand: device.brand,
      // model: device.model,
    );
  }

  Map<String, dynamic> toMap(Lookup assetType) {
    return {
      'id': id,
      'assetSerialNo': serialNumber,
      'assetNumber': number,
      'modelDefinition': modelDefinition.toJson(),
      'site': hospital.toMap(),
      'AssetType': assetType.toMap(),
      "supplier": {"id": 0, "suppliername": "string"},
    };
  }
}
