import 'package:test_sa/models/generic_attachment_model.dart';
import 'package:test_sa/modules/internal_audit_module/models/engineer_data_model.dart';
import 'package:test_sa/modules/internal_audit_module/models/internal_audit_timer_model.dart';

class EquipmentInternalAuditDataModel {
  int? id;
  String? requestNo;
  String? createdDate;
  int? requestNoSequence;
  Auditor? auditor;
  Status? status;
  Asset? asset;
  AssignEmployee? assignEmployee;
  dynamic manufacture;
  String? remarks;
  List<EquipmentsFinding>? equipmentsFindings;
  List<GenericAttachmentModel>? attachments;
  EngineerData? engineerData;


  EquipmentInternalAuditDataModel({
    this.id,
    this.requestNo,
    this.createdDate,
    this.requestNoSequence,
    this.auditor,
    this.status,
    this.asset,
    this.assignEmployee,
    this.manufacture,
    this.remarks,
    this.equipmentsFindings,
    this.attachments,
    this.engineerData,
  });

  EquipmentInternalAuditDataModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    requestNo = json['requestNo'];
    createdDate = json['createdDate'];
    requestNoSequence = json['requestNoSequence'];
    auditor = json['auditor'] != null ? Auditor.fromJson(json['auditor']) : null;
    status = json['status'] != null ? Status.fromJson(json['status']) : null;
    asset = json['asset'] != null ? Asset.fromJson(json['asset']) : null;
    assignEmployee = json['assignEmployee'] != null ? AssignEmployee.fromJson(json['assignEmployee']) : null;
    manufacture = json['manufacture'];
    remarks = json['remarks'];
    if (json['equipmentsFindings'] != null) {
      equipmentsFindings = <EquipmentsFinding>[];
      json['equipmentsFindings'].forEach((v) {
        equipmentsFindings!.add(EquipmentsFinding.fromJson(v));
      });
    }
    attachments = json['attachments'] != null
        ? (json['attachments'] as List)
        .map((e) => GenericAttachmentModel.fromInternalAuditJson(e))
        .where((e) => e.name != null) // optional filter if you want to skip null names
        .toList()
        : [];
    engineerData = json['engineerData'] != null ? EngineerData.fromJson(json['engineerData']) : null;

  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['id'] = id;
    data['requestNo'] = requestNo;
    data['createdDate'] = createdDate;
    data['requestNoSequence'] = requestNoSequence;
    if (auditor != null) {
      data['auditor'] = auditor!.toJson();
    }
    if (status != null) {
      data['status'] = status!.toJson();
    }
    if (asset != null) {
      data['asset'] = asset!.toJson();
    }
    if (assignEmployee != null) {
      data['assignEmployee'] = assignEmployee!.toJson();
    }
    data['manufacture'] = manufacture;
    data['remarks'] = remarks;
    if (equipmentsFindings != null) {
      data['equipmentsFindings'] =
          equipmentsFindings!.map((v) => v.toJson()).toList();
    }
    if (attachments != null) {
      data['attachments'] = attachments!.whereType<GenericAttachmentModel>().map((v) => v.toInternalAuditJson()).toList();
    }
    if (engineerData != null) data['engineerData'] = engineerData!.toJson();
    return data;
  }
}

class Auditor {
  String? userId;
  String? userName;
  String? email;
  String? employeeId;
  int? languageId;
  String? extensionNo;
  String? phoneNumber;
  bool? isActive;

  Auditor({
    this.userId,
    this.userName,
    this.email,
    this.employeeId,
    this.languageId,
    this.extensionNo,
    this.phoneNumber,
    this.isActive,
  });

  Auditor.fromJson(Map<String, dynamic> json) {
    userId = json['userId'];
    userName = json['userName'];
    email = json['email'];
    employeeId = json['employeeId'];
    languageId = json['languageId'];
    extensionNo = json['extensionNo'];
    phoneNumber = json['phoneNumber'];
    isActive = json['isActive'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['userId'] = userId;
    data['userName'] = userName;
    data['email'] = email;
    data['employeeId'] = employeeId;
    data['languageId'] = languageId;
    data['extensionNo'] = extensionNo;
    data['phoneNumber'] = phoneNumber;
    data['isActive'] = isActive;
    return data;
  }
}

class Status {
  int? id;
  String? name;
  int? value;

  Status({this.id, this.name, this.value});

  Status.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    value = json['value'];
  }

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

class Asset {
  int? id;
  String? assetNumber;
  String? assetSerialNo;
  String? assetName;
  String? modelName;
  String? manufacturerName;
  String? siteName;
  int? siteId;
  String? modelDefinition;
  int? departmentId;
  String? departmentName;

  Asset({
    this.id,
    this.assetNumber,
    this.assetSerialNo,
    this.assetName,
    this.modelName,
    this.manufacturerName,
    this.siteName,
    this.siteId,
    this.modelDefinition,
    this.departmentId,
    this.departmentName,
  });

  Asset.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    assetNumber = json['assetNumber'];
    assetSerialNo = json['assetSerialNo'];
    assetName = json['assetName'];
    modelName = json['modelName'];
    manufacturerName = json['manufacturerName'];
    siteName = json['siteName'];
    siteId = json['siteId'];
    modelDefinition = json['modelDefinition'];
    departmentId = json['departmentId'];
    departmentName = json['departmentName'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['id'] = id;
    data['assetNumber'] = assetNumber;
    data['assetSerialNo'] = assetSerialNo;
    data['assetName'] = assetName;
    data['modelName'] = modelName;
    data['manufacturerName'] = manufacturerName;
    data['siteName'] = siteName;
    data['siteId'] = siteId;
    data['modelDefinition'] = modelDefinition;
    data['departmentId'] = departmentId;
    data['departmentName'] = departmentName;
    return data;
  }
}

class AssignEmployee {
  String? userId;
  String? userName;
  String? email;
  String? employeeId;
  int? languageId;
  String? extensionNo;
  String? phoneNumber;
  bool? isActive;

  AssignEmployee({
    this.userId,
    this.userName,
    this.email,
    this.employeeId,
    this.languageId,
    this.extensionNo,
    this.phoneNumber,
    this.isActive,
  });

  AssignEmployee.fromJson(Map<String, dynamic> json) {
    userId = json['userId'];
    userName = json['userName'];
    email = json['email'];
    employeeId = json['employeeId'];
    languageId = json['languageId'];
    extensionNo = json['extensionNo'];
    phoneNumber = json['phoneNumber'];
    isActive = json['isActive'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['userId'] = userId;
    data['userName'] = userName;
    data['email'] = email;
    data['employeeId'] = employeeId;
    data['languageId'] = languageId;
    data['extensionNo'] = extensionNo;
    data['phoneNumber'] = phoneNumber;
    data['isActive'] = isActive;
    return data;
  }
}

class EquipmentsFinding {
  int? id;
  Finding? finding;

  EquipmentsFinding({this.id, this.finding});

  EquipmentsFinding.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    finding = json['finding'] != null ? Finding.fromJson(json['finding']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['id'] = id;
    if (finding != null) {
      data['finding'] = finding!.toJson();
    }
    return data;
  }
}

class Finding {
  int? id;
  String? name;
  int? value;

  Finding({this.id, this.name, this.value});

  Finding.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    value = json['value'];
  }

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