class GatewayModel {
  final String uuid;
  final bool switchAlarmSound;
  final String masterState;
  final bool factoryReset;
  final String alarmActive;

  GatewayModel({
    required this.uuid,
    required this.switchAlarmSound,
    required this.masterState,
    required this.factoryReset,
    required this.alarmActive,
  });

  factory GatewayModel.fromJson(Map<String, dynamic> json) {
    final status = json['status'] as List<dynamic>? ?? <dynamic>[];

    bool? switchAlarmSound;
    String? masterState;
    bool? factoryReset;
    String? alarmActive;

    for (final item in status) {
      switch (item['code']) {
        case 'switch_alarm_sound':
          switchAlarmSound = item['value'] as bool;
          break;
        case 'master_state':
          masterState = item['value'] as String;
          break;
        case 'factory_reset':
          factoryReset = item['value'] as bool;
          break;
        case 'alarm_active':
          alarmActive = item['value'] as String;
          break;
      }
    }

    return GatewayModel(
      uuid: json['uuid'] as String? ?? '',
      switchAlarmSound: switchAlarmSound ?? false,
      masterState: masterState ?? '',
      factoryReset: factoryReset ?? false,
      alarmActive: alarmActive ?? '',
    );
  }
}
