import 'package:syncrow_app/features/devices/model/status_model.dart';

class SmartDoorModel {
  int unlockFingerprint;
  int unlockPassword;
  int unlockTemporary;
  int unlockCard;
  String unlockAlarm;
  int unlockRequest;
  int residualElectricity;
  bool reverseLock;
  int unlockApp;
  bool hijack;
  bool doorbell;
  String unlockOfflinePd;
  String unlockOfflineClear;
  String unlockDoubleKit;
  String remoteNoPdSetkey;
  String remoteNoDpKey;
  bool normalOpenSwitch;

  SmartDoorModel(
      {required this.unlockFingerprint,
      required this.unlockPassword,
      required this.unlockTemporary,
      required this.unlockCard,
      required this.unlockAlarm,
      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 SmartDoorModel.fromJson(List<StatusModel> jsonList) {
    int _unlockFingerprint = 0;
    int _unlockPassword = 0;
    int _unlockTemporary = 0;
    int _unlockCard = 0;
    String _unlockAlarm = '';
    int _unlockRequest = 0;
    int _residualElectricity = 0;
    bool _reverseLock = false;
    int _unlockApp = 0;
    bool _hijack = false;
    bool _doorbell = false;
    String _unlockOfflinePd = '';
    String _unlockOfflineClear = '';
    String _unlockDoubleKit = '';
    String _remoteNoPdSetkey = '';
    String _remoteNoDpKey = '';
    bool _normalOpenSwitch = false;

    for (int i = 0; i < jsonList.length; i++) {
      if (jsonList[i].code == 'unlock_fingerprint') {
        _unlockFingerprint = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'unlock_password') {
        _unlockPassword = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'unlock_temporary') {
        _unlockTemporary = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'unlock_card') {
        _unlockCard = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'alarm_lock') {
        _unlockAlarm = jsonList[i].value ?? '';
      } else if (jsonList[i].code == 'unlock_request') {
        _unlockRequest = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'residual_electricity') {
        _residualElectricity = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'reverse_lock') {
        _reverseLock = jsonList[i].value ?? false;
      } else if (jsonList[i].code == 'unlock_app') {
        _unlockApp = jsonList[i].value ?? 0;
      } else if (jsonList[i].code == 'hijack') {
        _hijack = jsonList[i].value ?? false;
      } else if (jsonList[i].code == 'doorbell') {
        _doorbell = jsonList[i].value ?? false;
      } else if (jsonList[i].code == 'unlock_offline_pd') {
        _unlockOfflinePd = jsonList[i].value ?? '';
      } else if (jsonList[i].code == 'unlock_offline_clear') {
        _unlockOfflineClear = jsonList[i].value ?? '';
      } else if (jsonList[i].code == 'unlock_double_kit') {
        _unlockDoubleKit = jsonList[i].value ?? '';
      } else if (jsonList[i].code == 'remote_no_pd_setkey') {
        _remoteNoPdSetkey = jsonList[i].value ?? '';
      } else if (jsonList[i].code == 'remote_no_dp_key') {
        _remoteNoDpKey = jsonList[i].value ?? '';
      } else if (jsonList[i].code == 'normal_open_switch') {
        _normalOpenSwitch = jsonList[i].value ?? false;
      }
    }
    return SmartDoorModel(
        unlockFingerprint: _unlockFingerprint,
        unlockPassword: _unlockPassword,
        unlockTemporary: _unlockTemporary,
        unlockCard: _unlockCard,
        unlockAlarm: _unlockAlarm,
        unlockRequest: _unlockRequest,
        residualElectricity: _residualElectricity,
        reverseLock: _reverseLock,
        unlockApp: _unlockApp,
        hijack: _hijack,
        doorbell: _doorbell,
        unlockOfflinePd: _unlockOfflinePd,
        unlockOfflineClear: _unlockOfflineClear,
        unlockDoubleKit: _unlockDoubleKit,
        remoteNoPdSetkey: _remoteNoPdSetkey,
        remoteNoDpKey: _remoteNoDpKey,
        normalOpenSwitch: _normalOpenSwitch);
  }
}
