Files
syncrow-web/lib/pages/device_managment/water_heater/models/send_schedule.dart
2024-09-22 14:17:52 +03:00

94 lines
1.9 KiB
Dart

import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
/*
{
"category": "kg",
"time": "2024-09-22T10:31:54Z",
"function": {
"code": "switch_1",
"value": true
},
"days": [
"Sun"
]
}
*/
class SendSchedule {
final String category;
final String time;
final Status function;
final List<String> days;
SendSchedule({
required this.category,
required this.time,
required this.function,
required this.days,
});
SendSchedule copyWith({
String? category,
String? time,
Status? function,
List<String>? days,
}) {
return SendSchedule(
category: category ?? this.category,
time: time ?? this.time,
function: function ?? this.function,
days: days ?? this.days,
);
}
Map<String, dynamic> toMap() {
return {
'category': category,
'time': time,
'function': function.toMap(),
'days': days,
};
}
factory SendSchedule.fromMap(Map<String, dynamic> map) {
return SendSchedule(
category: map['category'] ?? '',
time: map['time'] ?? '',
function: Status.fromMap(map['function']),
days: List<String>.from(map['days']),
);
}
String toJson() => json.encode(toMap());
factory SendSchedule.fromJson(String source) =>
SendSchedule.fromMap(json.decode(source));
@override
String toString() {
return 'SendSchedule(category: $category, time: $time, function: $function, days: $days)';
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is SendSchedule &&
other.category == category &&
other.time == time &&
other.function == function &&
listEquals(other.days, days);
}
@override
int get hashCode {
return category.hashCode ^
time.hashCode ^
function.hashCode ^
days.hashCode;
}
}