import 'dart:typed_data';

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

import '../../controllers/api_routes/urls.dart';
import '../call_request_for_work_order_model.dart';

@Deprecated("Use the new model [lib/models/new_models/gas_refill_model.dart]")
class GasRefillModel {
  int id;

  //String userId;
  String clientName;
  String title;
  Lookup status;
  Lookup building;
  Lookup floor;
  Department department;
  List<GasRefillDetails> details;
  AssignedEmployee assignedEmployee;
  String signatureNurse;
  String signatureEngineer;
  Uint8List localNurseSignature;
  Uint8List localEngineerSignature;
  num workingHours;
  DateTime startDate, endDate, expectedDate;

  GasRefillModel({
    this.id,
    //this.userId,
    this.clientName,
    this.title,
    this.status,
    this.details,
    this.building,
    this.floor,
    this.startDate,
    this.endDate,
    this.expectedDate,
    this.department,
    this.assignedEmployee,
    this.signatureNurse,
    this.signatureEngineer,
    this.localEngineerSignature,
    this.localNurseSignature,
    this.workingHours,
  });

  bool validate() {
    if (title == null) return false;
    if (status == null) return false;
    // if (building == null) return false;
    // if (floor == null) return false;
    // if (department == null) return false;
    // if (startDate == null) return false;
    // if (endDate == null) return false;
    if (details == null && details.isEmpty) return false;
    return true;
  }

  fromGasRefillModel(GasRefillModel model) {
    id = model.id;
    //userId = model.userId;
    clientName = model.clientName;
    title = model.title;
    status = Lookup.fromStatus(model.status);
    details = model.details.map((e) => GasRefillDetails.fromDetails(e)).toList();
    building = model.building;
    floor = model.floor;
    department = model.department;
    startDate = model.startDate;
    endDate = model.endDate;
    expectedDate = model.expectedDate;
    assignedEmployee = model.assignedEmployee;
    localEngineerSignature = model.localEngineerSignature;
    localNurseSignature = model.localNurseSignature;
    signatureEngineer = model.signatureEngineer;
    signatureNurse = model.signatureNurse;
    workingHours = model.workingHours;
  }

  factory GasRefillModel.fromJson(Map<String, dynamic> parsedJson) {
    List<GasRefillDetails> details = [];
    if (parsedJson["gazRefillDetails"] != null) {
      List list = parsedJson["gazRefillDetails"];
      details = list.map((e) => GasRefillDetails.fromJson(e)).toList();
    }
    return GasRefillModel(
      id: parsedJson["id"],
      //userId: parsedJson["uid"],
      title: parsedJson["gazRefillNo"],
      clientName: parsedJson["site"] == null ? null : parsedJson["site"]["custName"],
      status: Lookup.fromJson(parsedJson["status"] ?? {}),
      details: details,
      building: Lookup.fromJson(parsedJson["building"] ?? {}),
      floor: Lookup.fromJson(parsedJson["floor"] ?? {}),
      department: Department.fromJson(parsedJson["department"] ?? {}),
      startDate: DateTime.tryParse(parsedJson['startDate'] ?? ""),
      endDate: DateTime.tryParse(parsedJson['endDate'] ?? ""),
      expectedDate: DateTime.tryParse(parsedJson['expectedDate'] ?? ""),
      assignedEmployee: AssignedEmployee.fromJson(parsedJson['assignedEmployee'] ?? {}),
      signatureEngineer: URLs.getFileUrl(parsedJson["engSignature"]),
      signatureNurse: URLs.getFileUrl(parsedJson["nurseSignature"]),
      workingHours: parsedJson["workingHours"],
    );
  }
}
