import 'dart:developer';

import 'package:test_sa/models/generic_attachment_model.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/new_models/building.dart';
import 'package:test_sa/models/new_models/floor.dart';
import 'package:test_sa/models/new_models/room_model.dart';
import 'package:test_sa/models/new_models/site.dart';
import 'package:test_sa/models/service_request/supplier_details.dart';
import '../../../models/new_models/department.dart';

class AssetInventoryResponse {
  num? totalRows;
  num? count;
  String? message;
  String? title;
  String? innerMessage;
  num? responseCode;
  bool? isSuccess;
  List<AssetInventoryModel>? assetList;

  AssetInventoryResponse({
    this.totalRows,
    this.count,
    this.message,
    this.title,
    this.innerMessage,
    this.responseCode,
    this.isSuccess,
    this.assetList,
  });

  AssetInventoryResponse.fromJson(Map<String, dynamic> json) {
    totalRows = json['totalRows'];
    count = json['count'];
    message = json['message'];
    title = json['title'];
    innerMessage = json['innerMessage'];
    responseCode = json['responseCode'];
    isSuccess = json['isSuccess'];
    if (json['data'] != null) {
      assetList = (json['data'] as List).map((item) => AssetInventoryModel.fromJson(item)).toList();
    }
  }

  Map<String, dynamic> toJson() {
    return {
      'totalRows': totalRows,
      'count': count,
      'message': message,
      'title': title,
      'innerMessage': innerMessage,
      'responseCode': responseCode,
      'isSuccess': isSuccess,
    };
  }
}

class AssetInventoryModel {
  num? id;
  num? assetId;
  String? transactionDate;
  String? assetNumber;
  String? serialNo;
  String? assetName;
  num? assetNameId;
  String? model;
  String? manufacturer;
  String? supplierName;
  String? siteName;
  String? buildingName;
  String? floorName;
  String? departmentName;
  String? roomName;
  num? statusId;
  String? status;
  num? statusValue;
  num? statusByAdminId;
  String? statusByAdmin;
  num? statusByAdminValue;
  bool? isNotRegistered;
  num? sessionId;
  num? assetImportId;
  num? siteId;
  num? supplierId;
  num? buildingId;
  num? floorId;
  num? departmentId;
  num? roomId;
  String? newAssetNumber;
  String? newSerialNo;
  num? newAssetNameId;
  String? newAssetNameText;
  num? newModelId;
  String? newModelName;
  num? manufacturerId;
  num? modelId;
  num? newManufacturerId;
  String? newManufacturerName;
  num? newSupplierId;
  String? newSupplierName;
  String? photo;
  String? photoOriginName;
  String? remarks;
  Site? site;
  Building? building;
  Floor? floor;
  Department? department;
  Rooms? room;
  SupplierDetails? supplier;
  List<GenericAttachmentModel> assetInventoryDetailAssetAttachments = [];

  AssetInventoryModel({
    this.id,
    this.sessionId,
    this.assetId,
    this.transactionDate,
    this.assetNumber,
    this.assetNameId,
    this.serialNo,
    this.assetName,
    this.model,
    this.manufacturer,
    this.supplierName,
    this.siteName,
    this.buildingName,
    this.floorName,
    this.departmentName,
    this.roomName,
    this.statusId,
    this.status,
    this.statusValue,
    this.statusByAdminId,
    this.statusByAdmin,
    this.statusByAdminValue,
    this.isNotRegistered,
    this.assetImportId,
    this.siteId,
    this.buildingId,
    this.floorId,
    this.departmentId,
    this.supplierId,
    this.roomId,
    this.newAssetNumber,
    this.manufacturerId,
    this.newSerialNo,
    this.newAssetNameId,
    this.newAssetNameText,
    this.newModelId,
    this.modelId,
    this.newModelName,
    this.newManufacturerId,
    this.newManufacturerName,
    this.newSupplierId,
    this.newSupplierName,
    this.photo,
    this.photoOriginName,
    this.remarks,
    this.site,
    this.department,
    this.building,
    this.floor,
    this.room,
    this.supplier,
    this.assetInventoryDetailAssetAttachments = const [],
  });

  AssetInventoryModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    assetId = json['assetId'];
    transactionDate = json['transactionDate'];
    assetNumber = json['assetNumber'];
    assetNameId = json['assetNameId'];
    serialNo = json['serialNo'];
    assetName = json['assetName'];
    model = json['model'] ?? json['modelName'];
    manufacturer = json['manufacturer'] ?? json['manufacturerName'];
    supplierName = json['supplierName'];
    siteName = json['site'] ?? json['siteName'];
    buildingName = json['building'] ?? json['buildingName'];
    floorName = json['floor'] ?? json['floorName'];
    departmentName = json['department'] ?? json['departmentName'];
    roomName = json['room'] ?? json['roomName'];
    statusId = json['statusId'];
    status = json['status'] ?? json['classification'];
    statusValue = json['statusValue'];
    isNotRegistered = json['isNotRegistered'];
    sessionId = json['sessionId'];
    assetImportId = json['assetImportId']??json['id'];
    siteId = json['siteId'];
    buildingId = json['buildingId'];
    floorId = json['floorId'];
    supplierId = json['supplierId'];
    departmentId = json['departmentId'];
    roomId = json['roomId'];
    modelId = json['modelId'];
    photo = json['photo'];
    photoOriginName = json['photoOriginName'];
    remarks = json['remarks'];
    if (json['assetInventoryDetailAssetAttachments'] != null) {
      assetInventoryDetailAssetAttachments = [];
      json['assetInventoryDetailAssetAttachments'].forEach((v) {
        assetInventoryDetailAssetAttachments.add(GenericAttachmentModel.fromAssetJson(v));
      });
    }

    //new data..
    // newAssetNumber = json['newAssetNumber'] ?? json['assetNumber'];
    // manufacturerId = json['manufacturerId'] ?? json['manufacturerId'];
    // newSerialNo = json['newSerialNo'] ?? json['serialNo'];
    // newAssetNameId = json['newAssetNameId'] ?? json['assetNameId'];
    // newAssetNameText = json['newAssetNameText'] ?? json['assetNameText'];
    // newModelId = json['newModelId'] ?? json['modelId'];
    // newModelName = json['newModelName'] ?? json['modelName'];
    // newManufacturerId = json['newManufacturerId'] ?? json['manufacturerId'];
    // newManufacturerName = json['newManufacturerName'] ?? json['manufacturerName'];
    // newSupplierId = json['newSupplierId'] ?? json['supplierId'];
    // newSupplierName = json['newSupplierName'] ?? json['supplierName'];
  }

  Map<String, dynamic> toJson() {
    return {
      'isNotRegistered': isNotRegistered,
      'sessionId': sessionId,
      'assetImportId': assetImportId,
      'transactionDate': transactionDate,
      'assetId': assetId,
      'siteId': siteId,
      'buildingId': buildingId,
      'floorId': floorId,
      'departmentId': departmentId,
      'roomId': roomId,
      'newSerialNo': newSerialNo,
      'newAssetNameId': newAssetNameId,
      'newAssetNameText': newAssetNameText,
      'newAssetNumber': newAssetNumber,
      'newModelId': newModelId,
      'newModelName': newModelName,
      'newManufacturerId': newManufacturerId,
      'newManufacturerName': newManufacturerName,
      'newSupplierId': newSupplierId,
      'newSupplierName': newSupplierName,
      'photo': photo,
      'remarks': remarks,
      'assetInventoryDetailAssetAttachments': assetInventoryDetailAssetAttachments != null
          ? assetInventoryDetailAssetAttachments!.map((v) => v?.toAssetJson() ?? {}).toList()
          : [],
    };
  }

  AssetInventoryModel mergeWith(AssetInventoryModel? other) {
    if (other == null) return this;

    return AssetInventoryModel(
      id: id ?? other.id,
      assetId: assetId ?? other.assetId,
      transactionDate: transactionDate ?? other.transactionDate,
      assetNumber: assetNumber ?? other.assetNumber,
      serialNo: serialNo ?? other.serialNo,
      assetName: assetName ?? other.assetName,
      assetNameId: assetNameId ?? other.assetNameId,
      model: model ?? other.model,
      manufacturer: manufacturer ?? other.manufacturer,
      supplierName: supplierName ?? other.supplierName,
      siteName: siteName ?? other.siteName,
      buildingName: buildingName ?? other.buildingName,
      floorName: floorName ?? other.floorName,
      departmentName: departmentName ?? other.departmentName,
      roomName: roomName ?? other.roomName,
      statusId: statusId ?? other.statusId,
      status: status ?? other.status,
      statusValue: statusValue ?? other.statusValue,
      statusByAdminId: statusByAdminId ?? other.statusByAdminId,
      statusByAdmin: statusByAdmin ?? other.statusByAdmin,
      statusByAdminValue: statusByAdminValue ?? other.statusByAdminValue,
      isNotRegistered: isNotRegistered ?? other.isNotRegistered,
      sessionId: sessionId ?? other.sessionId,
      assetImportId: assetImportId ?? other.assetImportId,
      siteId: siteId ?? other.siteId,
      supplierId: supplierId ?? other.supplierId,
      buildingId: buildingId ?? other.buildingId,
      floorId: floorId ?? other.floorId,
      departmentId: departmentId ?? other.departmentId,
      roomId: roomId ?? other.roomId,
      newAssetNumber: newAssetNumber ?? other.newAssetNumber,
      newSerialNo: newSerialNo ?? other.newSerialNo,
      newAssetNameId: newAssetNameId ?? other.newAssetNameId,
      newAssetNameText: newAssetNameText ?? other.newAssetNameText,
      newModelId: newModelId ?? other.newModelId,
      newModelName: newModelName ?? other.newModelName,
      manufacturerId: manufacturerId ?? other.manufacturerId,
      modelId: modelId ?? other.modelId,
      newManufacturerId: newManufacturerId ?? other.newManufacturerId,
      newManufacturerName: newManufacturerName ?? other.newManufacturerName,
      newSupplierId: newSupplierId ?? other.newSupplierId,
      newSupplierName: newSupplierName ?? other.newSupplierName,
      photo: photo ?? other.photo,
      photoOriginName: photoOriginName ?? other.photoOriginName,
      remarks: remarks ?? other.remarks,
      site: site ?? other.site,
      building: building ?? other.building,
      floor: floor ?? other.floor,
      department: department ?? other.department,
      room: room ?? other.room,
      supplier: supplier ?? other.supplier,
      assetInventoryDetailAssetAttachments: assetInventoryDetailAssetAttachments??other.assetInventoryDetailAssetAttachments,
    );
  }


}
