import 'dart:convert';

class DeviceStatus {
  final String productUuid;
  final String productType;
  final List<Status> status;

  DeviceStatus({
    required this.productUuid,
    required this.productType,
    required this.status,
  });

  factory DeviceStatus.fromMap(Map<String, dynamic> map) {
    return DeviceStatus(
      productUuid: map['productUuid'] ?? '',
      productType: map['productType'] ?? '',
      status: List<Status>.from(
          map['status']?.map((x) => Status.fromMap(x)) ?? const []),
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'productUuid': productUuid,
      'productType': productType,
      'status': status.map((x) => x.toMap()).toList(),
    };
  }

  factory DeviceStatus.fromJson(Map<String, dynamic> json) =>
      DeviceStatus.fromMap(json);

  String toJson() => json.encode(toMap());
}

class Status {
  final String code;
  final dynamic value;

  Status({
    required this.code,
    required this.value,
  });

  factory Status.fromMap(Map<String, dynamic> map) {
    return Status(
      code: map['code'] ?? '',
      value: map['value'],
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'code': code,
      'value': value,
    };
  }

  factory Status.fromJson(String source) => Status.fromMap(json.decode(source));

  String toJson() => json.encode(toMap());
  Status copyWith({
    String? code,
    dynamic value,
  }) {
    return Status(
      code: code ?? this.code,
      value: value ?? this.value,
    );
  }
}
