import '../lookup.dart';

class CalibrationTool {
  Lookup? assetsNumber;
  DateTime? dataOfTesting;

  CalibrationTool({
    this.assetsNumber,
    this.dataOfTesting,
  });

  Map<String, String> toMap() {
    return {
      if (assetsNumber != null) 'assetsSN': (assetsNumber?.id).toString(),
      if (dataOfTesting != null) 'dataOfTesting': ((dataOfTesting?.millisecondsSinceEpoch ?? 0) ~/ 1000).toString(),
    };
  }

  factory CalibrationTool.fromMap(Map<String, dynamic> map) {
    return CalibrationTool(
      assetsNumber: Lookup.fromJson(map['assetsSN']),
      dataOfTesting: map['dataOfTesting'] == null || map['dataOfTesting'] == ""
          ? null
          : DateTime.fromMillisecondsSinceEpoch(
              (int.tryParse(map['dataOfTesting']) ?? 0) * 1000,
            ),
    );
  }
}
