/* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD SPDX-License-Identifier: MIT */ import 'dart:convert'; class BlueWifi { String? ssid; String? password; BlueWifi({this.ssid, this.password}); Map toMap() { return {'ssid': ssid, 'password': password}; } factory BlueWifi.fromMap(Map map) { return BlueWifi(ssid: map['ssid'], password: map['password']); } } class BlueEncryptionDecryption { String? cmd; String? data; //defaultConstructorfunction BlueEncryptionDecryption({this.cmd, this.data}); //fromJson Constructorfunction:from JSON mapcreateinstance BlueEncryptionDecryption.fromJson(Map json) { //safefrom JSON inValue,avoidtypeerror cmd = json['cmd'] as String?; data = json['data'] as String?; } //optional:toJson method(Convenientwillobjecttoas JSON) Map toJson() { final Map json = {}; if (cmd != null) { json['cmd'] = cmd; } if (data != null) { json['data'] = data; } return json; } //toString method:Stringoutput @override String toString() { return '{\n' ' cmd: $cmd,\n' ' data: $data\n' '}'; } //optional:enhance toString(output,Debug) String toStringFormatted() { return 'BlueEncryptionDecryption {\n' ' cmd: "${cmd ?? 'null'}"\n' ' data: "${data ?? 'null'}"\n' '}'; } } class BlueWifiModel { String? cmd; BlueWifi? data; BlueWifiModel({this.cmd, this.data}); Map toMap() { return {'cmd': cmd, 'data': data?.toMap()}; } String? toJson() { try { return const JsonEncoder.withIndent(' ').convert(toMap()); } catch (_) { return null; } } static BlueWifiModel? fromJson(String json) { try { final map = jsonDecode(json) as Map; return BlueWifiModel( cmd: map['cmd'], data: map['data'] != null ? BlueWifi.fromMap(map['data']) : null, ); } catch (_) { return null; } } } class BlueNotifyState { int? type; String? state; BlueNotifyState({this.type, this.state}); Map toMap() { return {'type': type, 'state': state}; } factory BlueNotifyState.fromMap(Map map) { return BlueNotifyState(type: map['type'], state: map['state']); } } class BlueNotifyStateModel { String? cmd; BlueNotifyState? data; BlueNotifyStateModel({this.cmd, this.data}); Map toMap() { return {'cmd': cmd, 'data': data?.toMap()}; } String? toJson() { try { return const JsonEncoder.withIndent(' ').convert(toMap()); } catch (_) { return null; } } static BlueNotifyStateModel? fromJson(String json) { try { final map = jsonDecode(json) as Map; return BlueNotifyStateModel( cmd: map['cmd'], data: map['data'] != null ? BlueNotifyState.fromMap(map['data']) : null, ); } catch (_) { return null; } } }