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

class CalibrationTool {
  int id;
  Lookup assetsNumber;
  DateTime dataOfTesting;

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

  Map<String, dynamic> toMap(int visitId) {
    return {
      "id": id ?? 0,
      "visitId": visitId,
      if (assetsNumber != null) 'assetId': (assetsNumber?.id).toString(),
      if (dataOfTesting != null) 'calibrationDateOfTesters': dataOfTesting.toIso8601String(),
    };
  }

  factory CalibrationTool.fromMap(Map<String, dynamic> map) {
    return CalibrationTool(
      assetsNumber: Lookup(id: map["assetId"], name: map['assetNumber']),
      dataOfTesting: DateTime.tryParse(map['calibrationDateOfTesters'] ?? ""),
    );
  }

  CalibrationTool copyWith({
    Lookup assetsNumber,
    DateTime dataOfTesting,
  }) {
    return CalibrationTool(
      id: id,
      assetsNumber: assetsNumber ?? this.assetsNumber,
      dataOfTesting: dataOfTesting ?? this.dataOfTesting,
    );
  }
}
