import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';

class DoorLockStatusModel {
  final String uuid;
  final int unlockFingerprint;
  final int unlockPassword;
  final int unlockTemporary;
  final int unlockCard;
  final String alarmLock;
  final int unlockRequest;
  final int residualElectricity;
  final bool reverseLock;
  final int unlockApp;
  final bool hijack;
  final bool doorbell;
  final String unlockOfflinePd;
  final String unlockOfflineClear;
  final String unlockDoubleKit;
  final String remoteNoPdSetkey;
  final String remoteNoDpKey;
  bool normalOpenSwitch;

  DoorLockStatusModel({
    required this.uuid,
    required this.unlockFingerprint,
    required this.unlockPassword,
    required this.unlockTemporary,
    required this.unlockCard,
    required this.alarmLock,
    required this.unlockRequest,
    required this.residualElectricity,
    required this.reverseLock,
    required this.unlockApp,
    required this.hijack,
    required this.doorbell,
    required this.unlockOfflinePd,
    required this.unlockOfflineClear,
    required this.unlockDoubleKit,
    required this.remoteNoPdSetkey,
    required this.remoteNoDpKey,
    required this.normalOpenSwitch,
  });

  factory DoorLockStatusModel.fromJson(String id, List<Status> jsonList) {
    late int unlockFingerprint;
    late int unlockPassword;
    late int unlockTemporary;
    late int unlockCard;
    late String alarmLock;
    late int unlockRequest;
    late int residualElectricity;
    late bool reverseLock;
    late int unlockApp;
    late bool hijack;
    late bool doorbell;
    late String unlockOfflinePd;
    late String unlockOfflineClear;
    late String unlockDoubleKit;
    late String remoteNoPdSetkey;
    late String remoteNoDpKey;
    late bool normalOpenSwitch;

    for (var status in jsonList) {
      switch (status.code) {
        case 'unlock_fingerprint':
          unlockFingerprint = status.value ?? 0;
          break;
        case 'unlock_password':
          unlockPassword = status.value ?? 0;
          break;
        case 'unlock_temporary':
          unlockTemporary = status.value ?? 0;
          break;
        case 'unlock_card':
          unlockCard = status.value ?? 0;
          break;
        case 'alarm_lock':
          alarmLock = status.value ?? '';
          break;
        case 'unlock_request':
          unlockRequest = status.value ?? 0;
          break;
        case 'residual_electricity':
          residualElectricity = status.value ?? 0;
          break;
        case 'reverse_lock':
          reverseLock = status.value ?? false;
          break;
        case 'unlock_app':
          unlockApp = status.value ?? 0;
          break;
        case 'hijack':
          hijack = status.value ?? false;
          break;
        case 'doorbell':
          doorbell = status.value ?? false;
          break;
        case 'unlock_offline_pd':
          unlockOfflinePd = status.value ?? '';
          break;
        case 'unlock_offline_clear':
          unlockOfflineClear = status.value ?? '';
          break;
        case 'unlock_double_kit':
          unlockDoubleKit = status.value ?? '';
          break;
        case 'remote_no_pd_setkey':
          remoteNoPdSetkey = status.value ?? '';
          break;
        case 'remote_no_dp_key':
          remoteNoDpKey = status.value ?? '';
          break;
        case 'normal_open_switch':
          normalOpenSwitch = status.value ?? false;
          break;
        default:
          break;
      }
    }

    return DoorLockStatusModel(
      uuid: id,
      unlockFingerprint: unlockFingerprint,
      unlockPassword: unlockPassword,
      unlockTemporary: unlockTemporary,
      unlockCard: unlockCard,
      alarmLock: alarmLock,
      unlockRequest: unlockRequest,
      residualElectricity: residualElectricity,
      reverseLock: reverseLock,
      unlockApp: unlockApp,
      hijack: hijack,
      doorbell: doorbell,
      unlockOfflinePd: unlockOfflinePd,
      unlockOfflineClear: unlockOfflineClear,
      unlockDoubleKit: unlockDoubleKit,
      remoteNoPdSetkey: remoteNoPdSetkey,
      remoteNoDpKey: remoteNoDpKey,
      normalOpenSwitch: normalOpenSwitch,
    );
  }

  DoorLockStatusModel copyWith({
    String? uuid,
    int? unlockFingerprint,
    int? unlockPassword,
    int? unlockTemporary,
    int? unlockCard,
    String? alarmLock,
    int? unlockRequest,
    int? residualElectricity,
    bool? reverseLock,
    int? unlockApp,
    bool? hijack,
    bool? doorbell,
    String? unlockOfflinePd,
    String? unlockOfflineClear,
    String? unlockDoubleKit,
    String? remoteNoPdSetkey,
    String? remoteNoDpKey,
    bool? normalOpenSwitch,
  }) {
    return DoorLockStatusModel(
      uuid: uuid ?? this.uuid,
      unlockFingerprint: unlockFingerprint ?? this.unlockFingerprint,
      unlockPassword: unlockPassword ?? this.unlockPassword,
      unlockTemporary: unlockTemporary ?? this.unlockTemporary,
      unlockCard: unlockCard ?? this.unlockCard,
      alarmLock: alarmLock ?? this.alarmLock,
      unlockRequest: unlockRequest ?? this.unlockRequest,
      residualElectricity: residualElectricity ?? this.residualElectricity,
      reverseLock: reverseLock ?? this.reverseLock,
      unlockApp: unlockApp ?? this.unlockApp,
      hijack: hijack ?? this.hijack,
      doorbell: doorbell ?? this.doorbell,
      unlockOfflinePd: unlockOfflinePd ?? this.unlockOfflinePd,
      unlockOfflineClear: unlockOfflineClear ?? this.unlockOfflineClear,
      unlockDoubleKit: unlockDoubleKit ?? this.unlockDoubleKit,
      remoteNoPdSetkey: remoteNoPdSetkey ?? this.remoteNoPdSetkey,
      remoteNoDpKey: remoteNoDpKey ?? this.remoteNoDpKey,
      normalOpenSwitch: normalOpenSwitch ?? this.normalOpenSwitch,
    );
  }
}
