138 lines
4.8 KiB
Dart
138 lines
4.8 KiB
Dart
// 功能:家庭成员、设备及共享权限领域模型;版本:1.0.0。
|
||
|
||
class FamilyDevicePermission {
|
||
const FamilyDevicePermission({
|
||
required this.deviceIdentity,
|
||
required this.deviceName,
|
||
required this.deviceKind,
|
||
required this.canView,
|
||
required this.canAlert,
|
||
required this.canControl,
|
||
});
|
||
final String deviceIdentity, deviceName, deviceKind;
|
||
final bool canView, canAlert, canControl;
|
||
|
||
factory FamilyDevicePermission.fromJson(Map<String, Object?> json) => FamilyDevicePermission(
|
||
deviceIdentity: json['device_identity'] as String? ?? '',
|
||
deviceName: json['device_name'] as String? ?? '',
|
||
deviceKind: json['device_kind'] as String? ?? 'unknown',
|
||
canView: json['can_view'] == true,
|
||
canAlert: json['can_alert'] == true,
|
||
canControl: json['can_control'] == true,
|
||
);
|
||
|
||
Map<String, Object?> toJson() => {
|
||
'device_identity': deviceIdentity,
|
||
'can_view': canView,
|
||
'can_alert': canAlert,
|
||
'can_control': canControl,
|
||
};
|
||
}
|
||
|
||
class FamilyMember {
|
||
const FamilyMember({
|
||
required this.identity,
|
||
required this.name,
|
||
required this.phoneMasked,
|
||
required this.relationship,
|
||
required this.inviteStatus,
|
||
required this.isOwner,
|
||
required this.permissions,
|
||
this.expiresAt,
|
||
});
|
||
final String identity, name, phoneMasked, relationship;
|
||
final int inviteStatus;
|
||
final bool isOwner;
|
||
final List<FamilyDevicePermission> permissions;
|
||
final DateTime? expiresAt;
|
||
|
||
bool get pending => inviteStatus == 10;
|
||
factory FamilyMember.fromJson(Map<String, Object?> json) => FamilyMember(
|
||
identity: json['identity'] as String? ?? '',
|
||
name: json['name'] as String? ?? '',
|
||
phoneMasked: json['phone_masked'] as String? ?? '',
|
||
relationship: json['relationship'] as String? ?? '',
|
||
inviteStatus: (json['invite_status'] as num?)?.toInt() ?? 10,
|
||
isOwner: json['is_owner'] == true,
|
||
permissions: (json['device_permissions'] as List? ?? const [])
|
||
.whereType<Map<Object?, Object?>>()
|
||
.map((e) => FamilyDevicePermission.fromJson(Map<String, Object?>.from(e)))
|
||
.toList(),
|
||
expiresAt: DateTime.tryParse(json['expires_at'] as String? ?? ''),
|
||
);
|
||
}
|
||
|
||
class FamilyDevice {
|
||
const FamilyDevice({
|
||
required this.identity,
|
||
required this.name,
|
||
required this.kind,
|
||
required this.shareCount,
|
||
required this.mappingConfigured,
|
||
});
|
||
final String identity, name, kind;
|
||
final int shareCount;
|
||
final bool mappingConfigured;
|
||
factory FamilyDevice.fromJson(Map<String, Object?> json) => FamilyDevice(
|
||
identity: json['identity'] as String? ?? '',
|
||
name: json['name'] as String? ?? '',
|
||
kind: json['kind'] as String? ?? 'unknown',
|
||
shareCount: (json['share_count'] as num?)?.toInt() ?? 0,
|
||
mappingConfigured: json['mapping_configured'] == true,
|
||
);
|
||
}
|
||
|
||
class FamilyDashboardData {
|
||
const FamilyDashboardData({
|
||
required this.householdName,
|
||
required this.ownerName,
|
||
required this.memberCount,
|
||
required this.deviceCount,
|
||
required this.members,
|
||
required this.devices,
|
||
this.incomingInvitations = const [],
|
||
});
|
||
final String householdName, ownerName;
|
||
final int memberCount, deviceCount;
|
||
final List<FamilyMember> members;
|
||
final List<FamilyDevice> devices;
|
||
final List<FamilyInvitation> incomingInvitations;
|
||
factory FamilyDashboardData.fromJson(Map<String, Object?> json) => FamilyDashboardData(
|
||
householdName: json['household_name'] as String? ?? '我的家庭',
|
||
ownerName: json['owner_name'] as String? ?? '',
|
||
memberCount: (json['member_count'] as num?)?.toInt() ?? 0,
|
||
deviceCount: (json['device_count'] as num?)?.toInt() ?? 0,
|
||
members: (json['members'] as List? ?? const [])
|
||
.whereType<Map<Object?, Object?>>()
|
||
.map((e) => FamilyMember.fromJson(Map<String, Object?>.from(e)))
|
||
.toList(),
|
||
devices: (json['devices'] as List? ?? const [])
|
||
.whereType<Map<Object?, Object?>>()
|
||
.map((e) => FamilyDevice.fromJson(Map<String, Object?>.from(e)))
|
||
.toList(),
|
||
incomingInvitations: (json['incoming_invitations'] as List? ?? const [])
|
||
.whereType<Map<Object?, Object?>>()
|
||
.map((e) => FamilyInvitation.fromJson(Map<String, Object?>.from(e)))
|
||
.toList(),
|
||
);
|
||
}
|
||
|
||
class FamilyInvitation {
|
||
const FamilyInvitation({
|
||
required this.identity,
|
||
required this.ownerName,
|
||
required this.name,
|
||
required this.relationship,
|
||
required this.expiresAt,
|
||
});
|
||
final String identity, ownerName, name, relationship;
|
||
final DateTime? expiresAt;
|
||
factory FamilyInvitation.fromJson(Map<String, Object?> json) => FamilyInvitation(
|
||
identity: json['identity'] as String? ?? '',
|
||
ownerName: json['owner_name'] as String? ?? '',
|
||
name: json['name'] as String? ?? '',
|
||
relationship: json['relationship'] as String? ?? '',
|
||
expiresAt: DateTime.tryParse(json['expires_at'] as String? ?? ''),
|
||
);
|
||
}
|