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

class SosModel {
  String sosContactState;
  int batteryPercentage;

  SosModel({
    required this.sosContactState,
    required this.batteryPercentage,
  });

  factory SosModel.fromJson(List<StatusModel> jsonList) {
    String _sosContactState = '';
    int _batteryPercentage = 0;

    for (int i = 0; i < jsonList.length; i++) {
      if (jsonList[i].code == 'sos') {
        _sosContactState = jsonList[i].value ?? '';
      } else if (jsonList[i].code == 'battery_percentage') {
        _batteryPercentage = jsonList[i].value ?? 0;
      }
    }
    return SosModel(
      sosContactState: _sosContactState,
      batteryPercentage: _batteryPercentage,
    );
  }
}
