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

class TwoGangGlassStatusModel {
  final String uuid;
  final bool switch1;
  final int countDown1;
  final bool switch2;
  final int countDown2;

  TwoGangGlassStatusModel({
    required this.uuid,
    required this.switch1,
    required this.countDown1,
    required this.switch2,
    required this.countDown2,
  });

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

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

    return TwoGangGlassStatusModel(
      uuid: id,
      switch1: switch1,
      countDown1: countDown1,
      switch2: switch2,
      countDown2: countDown2,
    );
  }

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

  @override
  String toString() =>
      'TwoGangGlassStatusModel(uuid: $uuid, switch1: $switch1, countDown1: $countDown1, switch2: $switch2, countDown2: $countDown2)';
}
