import 'dart:developer';

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

class SystemInternalAuditFormModel {
  int? id;
  String? auditorId;
  String? assignEmployeeId;
  Lookup? findingType;
  String? findingDescription;
  Lookup? workOrderType;
  int? correctiveMaintenanceId;
  int? planPreventiveVisitId;
  int? assetTransferId;
  List<GenericAttachmentModel>? attachments = [];
  int? taskJobId;
  int? taskAlertJobId;
  int? gasRefillId;
  int? planRecurrentTaskId;
  int? statusId;
  SystemAuditWorkOrderDetailModel? workOrderDetailModel;

  SystemInternalAuditFormModel({
    this.id,
    this.auditorId,
    this.assignEmployeeId,
    this.findingType,
    this.findingDescription,
    this.workOrderType,
    this.correctiveMaintenanceId,
    this.planPreventiveVisitId,
    this.assetTransferId,
    this.taskJobId,
    this.taskAlertJobId,
    this.gasRefillId,
    this.planRecurrentTaskId,
    this.workOrderDetailModel,
    this.statusId,
    this.attachments,
  });

  Map<String, dynamic> toJson() {
    return {
      // 'id': id,
      'auditorId': auditorId,
      'assignEmployeeId': assignEmployeeId,
      'findingTypeId': findingType?.id,
      'findingDescription': findingDescription,
      'workOrderTypeId': workOrderType?.id,
      'correctiveMaintenanceId': correctiveMaintenanceId,
      'planPreventiveVisitId': planPreventiveVisitId,
      'assetTransferId': assetTransferId,
      'taskJobId': taskJobId,
      'taskAlertJobId': taskAlertJobId,
      'gasRefillId': gasRefillId,
      'planRecurrentTaskId': planRecurrentTaskId,
      'statusId': statusId,
      'attachments': attachments?.whereType<GenericAttachmentModel>().map((e) => e.toInternalAuditJson()).toList(),
    };
  }
}

class WoAutoCompleteModel {
  int? id;
  String? workOrderNo;
  String? displayName;

  WoAutoCompleteModel({this.id, this.workOrderNo, this.displayName});

  WoAutoCompleteModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    workOrderNo = json['workOrderNo'];
    displayName = json['workOrderNo'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['woOrderNo'] = workOrderNo;
    data['displayName'] = workOrderNo;
    return data;
  }
}

class SystemAuditWorkOrderDetailModel {
  String? createdBy;
  DateTime? createdDate;
  String? modifiedBy;
  DateTime? modifiedDate;
  int? id;
  String? workOrderNo;
  String? woAssignedEngineer;
  String? woAssetNo;
  String? wosn;
  String? woAssetName;
  String? woModel;
  String? woManufacturer;
  String? woSite;
  String? woDepartment;
  String? wOPMScheduleDate;
  String? wOPMActualVisitDate;
  String? wOAssetTransferDestinationSite;
  String? wOAssetTransferSenderEngineer;
  String? wOAssetTransferReceiverEngineer;
  String? wOTaskAlertJobImpactedStatus;
  String? wOTaskAlertJobAcknowledgment;
  String? wOGasRefillType;
  String? wORecurrentTaskTaskType;
  String? wORecurrentTaskPlanNo;
  String? wORecurrentTaskPlanName;
  String? wORecurrentTaskStatus;

  SystemAuditWorkOrderDetailModel({
    this.createdBy,
    this.createdDate,
    this.modifiedBy,
    this.modifiedDate,
    this.id,
    this.workOrderNo,
    this.woAssignedEngineer,
    this.woAssetNo,
    this.wosn,
    this.woAssetName,
    this.woModel,
    this.woManufacturer,
    this.woSite,
    this.woDepartment,
    this.wOPMScheduleDate,
    this.wOPMActualVisitDate,
    this.wOAssetTransferDestinationSite,
    this.wOAssetTransferSenderEngineer,
    this.wOAssetTransferReceiverEngineer,
    this.wOTaskAlertJobImpactedStatus,
    this.wOTaskAlertJobAcknowledgment,
    this.wOGasRefillType,
    this.wORecurrentTaskTaskType,
    this.wORecurrentTaskPlanNo,
    this.wORecurrentTaskPlanName,
    this.wORecurrentTaskStatus,
  });

  SystemAuditWorkOrderDetailModel.fromJson(Map<String, dynamic> json) {
    createdBy = json['createdBy'];
    createdDate = json['createdDate'] != null ? DateTime.tryParse(json['createdDate']) : null;
    modifiedBy = json['modifiedBy'];
    modifiedDate = json['modifiedDate'] != null ? DateTime.tryParse(json['modifiedDate']) : null;
    id = json['id'];
    workOrderNo = json['workOrderNo'];
    woAssignedEngineer = json['woAssignedEngineer'];
    woAssetNo = json['woAssetNo'];
    wosn = json['wosn'];
    woAssetName = json['woAssetName'];
    woModel = json['woModel'];
    woManufacturer = json['woManufacturer'];
    woSite = json['woSite'];
    woDepartment = json['woDepartment'];
    wOPMScheduleDate = json['wO_PM_ScheduleDate'];
    wOPMActualVisitDate = json['wO_PM_ActualVisitDate'];
    wOAssetTransferDestinationSite = json['wO_AssetTransfer_DestinationSite'];
    wOAssetTransferSenderEngineer = json['wO_AssetTransfer_SenderEngineer'];
    wOAssetTransferReceiverEngineer = json['wO_AssetTransfer_ReceiverEngineer'];
    wOTaskAlertJobImpactedStatus = json['wO_TaskAlertJob_ImpactedStatus'];
    wOTaskAlertJobAcknowledgment = json['wO_TaskAlertJob_Acknowledgment'];
    wOGasRefillType = json['wO_GasRefill_Type'];
    wORecurrentTaskTaskType = json['wO_RecurrentTask_TaskType'];
    wORecurrentTaskPlanNo = json['wO_RecurrentTask_PlanNo'];
    wORecurrentTaskPlanName = json['wO_RecurrentTask_PlanName'];
    wORecurrentTaskStatus = json['wO_RecurrentTask_Status'];
  }

  Map<String, dynamic> toJson() {
    return {
      'createdBy': createdBy,
      'createdDate': createdDate?.toIso8601String(),
      'modifiedBy': modifiedBy,
      'modifiedDate': modifiedDate?.toIso8601String(),
      'id': id,
      'workOrderNo': workOrderNo,
      'woAssignedEngineer': woAssignedEngineer,
      'woAssetNo': woAssetNo,
      'wosn': wosn,
      'woAssetName': woAssetName,
      'woModel': woModel,
      'woManufacturer': woManufacturer,
      'woSite': woSite,
      'woDepartment': woDepartment,
      'wO_PM_ScheduleDate': wOPMScheduleDate,
      'wO_PM_ActualVisitDate': wOPMActualVisitDate,
      'wO_AssetTransfer_DestinationSite': wOAssetTransferDestinationSite,
      'wO_AssetTransfer_SenderEngineer': wOAssetTransferSenderEngineer,
      'wO_AssetTransfer_ReceiverEngineer': wOAssetTransferReceiverEngineer,
      'wO_TaskAlertJob_ImpactedStatus': wOTaskAlertJobImpactedStatus,
      'wO_TaskAlertJob_Acknowledgment': wOTaskAlertJobAcknowledgment,
      'wO_GasRefill_Type': wOGasRefillType,
      'wO_RecurrentTask_TaskType': wORecurrentTaskTaskType,
      'wO_RecurrentTask_PlanNo': wORecurrentTaskPlanNo,
      'wO_RecurrentTask_PlanName': wORecurrentTaskPlanName,
      'wO_RecurrentTask_Status': wORecurrentTaskStatus,
    };
  }
}
