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

class TwoGangStatusModel {
  final String uuid;
  final bool switch1;
  final bool switch2;
  final int countDown;
  final int countDown2;

  TwoGangStatusModel({
    required this.uuid,
    required this.switch1,
    required this.switch2,
    required this.countDown,
    required this.countDown2,
  });

  factory TwoGangStatusModel.fromJson(String id, List<Status> jsonList) {
    late bool switch1;
    late bool switch2;
    late int countDown;
    late int countDown2;

    for (var status in jsonList) {
      switch (status.code) {
        case 'switch_1':
          switch1 = bool.tryParse(status.value.toString()) ?? false;
          break;
        case 'countdown_1':
          countDown = int.tryParse(status.value.toString()) ?? 0;
          break;
        case 'switch_2':
          switch2 = bool.tryParse(status.value.toString()) ?? false;
          break;
        case 'countdown_2':
          countDown2 = int.tryParse(status.value.toString()) ?? 0;
          break;
      }
    }

    return TwoGangStatusModel(
      uuid: id,
      switch1: switch1,
      countDown: countDown,
      switch2: switch2,
      countDown2: countDown2,
    );
  }

  TwoGangStatusModel copyWith({
    String? uuid,
    bool? switch1,
    int? countDown,
    bool? switch2,
    int? countDown2,
  }) {
    return TwoGangStatusModel(
      uuid: uuid ?? this.uuid,
      switch1: switch1 ?? this.switch1,
      countDown: countDown ?? this.countDown,
      switch2: switch2 ?? this.switch2,
      countDown2: countDown2 ?? this.countDown2,
    );
  }
}
