2025-01-30 21:12:57 -06:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
2026-08-05 12:00:49 -07:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
|
|
|
|
|
|
part 'person.model.freezed.dart';
|
|
|
|
|
|
2025-07-18 22:21:39 +08:00
|
|
|
// TODO: Remove PersonDto once Isar is removed
|
|
|
|
|
class PersonDto {
|
|
|
|
|
const PersonDto({
|
2024-09-24 14:50:21 +02:00
|
|
|
required this.id,
|
2025-01-30 21:12:57 -06:00
|
|
|
this.birthDate,
|
2024-09-24 14:50:21 +02:00
|
|
|
required this.isHidden,
|
|
|
|
|
required this.name,
|
|
|
|
|
required this.thumbnailPath,
|
|
|
|
|
this.updatedAt,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final String id;
|
|
|
|
|
final DateTime? birthDate;
|
|
|
|
|
final bool isHidden;
|
|
|
|
|
final String name;
|
|
|
|
|
final String thumbnailPath;
|
|
|
|
|
final DateTime? updatedAt;
|
2025-01-30 21:12:57 -06:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String toString() {
|
|
|
|
|
return 'Person(id: $id, birthDate: $birthDate, isHidden: $isHidden, name: $name, thumbnailPath: $thumbnailPath, updatedAt: $updatedAt)';
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-18 22:21:39 +08:00
|
|
|
PersonDto copyWith({
|
2025-01-30 21:12:57 -06:00
|
|
|
String? id,
|
|
|
|
|
DateTime? birthDate,
|
|
|
|
|
bool? isHidden,
|
|
|
|
|
String? name,
|
|
|
|
|
String? thumbnailPath,
|
|
|
|
|
DateTime? updatedAt,
|
|
|
|
|
}) {
|
2025-07-18 22:21:39 +08:00
|
|
|
return PersonDto(
|
2025-01-30 21:12:57 -06:00
|
|
|
id: id ?? this.id,
|
|
|
|
|
birthDate: birthDate ?? this.birthDate,
|
|
|
|
|
isHidden: isHidden ?? this.isHidden,
|
|
|
|
|
name: name ?? this.name,
|
|
|
|
|
thumbnailPath: thumbnailPath ?? this.thumbnailPath,
|
|
|
|
|
updatedAt: updatedAt ?? this.updatedAt,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
|
return <String, dynamic>{
|
|
|
|
|
'id': id,
|
|
|
|
|
'birthDate': birthDate?.millisecondsSinceEpoch,
|
|
|
|
|
'isHidden': isHidden,
|
|
|
|
|
'name': name,
|
|
|
|
|
'thumbnailPath': thumbnailPath,
|
|
|
|
|
'updatedAt': updatedAt?.millisecondsSinceEpoch,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-18 22:21:39 +08:00
|
|
|
factory PersonDto.fromMap(Map<String, dynamic> map) {
|
|
|
|
|
return PersonDto(
|
2025-01-30 21:12:57 -06:00
|
|
|
id: map['id'] as String,
|
2025-07-25 08:07:22 +05:30
|
|
|
birthDate: map['birthDate'] != null ? DateTime.fromMillisecondsSinceEpoch(map['birthDate'] as int) : null,
|
2025-01-30 21:12:57 -06:00
|
|
|
isHidden: map['isHidden'] as bool,
|
|
|
|
|
name: map['name'] as String,
|
|
|
|
|
thumbnailPath: map['thumbnailPath'] as String,
|
2025-07-25 08:07:22 +05:30
|
|
|
updatedAt: map['updatedAt'] != null ? DateTime.fromMillisecondsSinceEpoch(map['updatedAt'] as int) : null,
|
2025-01-30 21:12:57 -06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
|
|
2025-07-25 08:07:22 +05:30
|
|
|
factory PersonDto.fromJson(String source) => PersonDto.fromMap(json.decode(source) as Map<String, dynamic>);
|
2025-01-30 21:12:57 -06:00
|
|
|
|
|
|
|
|
@override
|
2025-07-18 22:21:39 +08:00
|
|
|
bool operator ==(covariant PersonDto other) {
|
2026-05-12 00:47:24 +07:00
|
|
|
if (identical(this, other)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-01-30 21:12:57 -06:00
|
|
|
|
|
|
|
|
return other.id == id &&
|
|
|
|
|
other.birthDate == birthDate &&
|
|
|
|
|
other.isHidden == isHidden &&
|
|
|
|
|
other.name == name &&
|
|
|
|
|
other.thumbnailPath == thumbnailPath &&
|
|
|
|
|
other.updatedAt == updatedAt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
int get hashCode {
|
|
|
|
|
return id.hashCode ^
|
|
|
|
|
birthDate.hashCode ^
|
|
|
|
|
isHidden.hashCode ^
|
|
|
|
|
name.hashCode ^
|
|
|
|
|
thumbnailPath.hashCode ^
|
|
|
|
|
updatedAt.hashCode;
|
|
|
|
|
}
|
2024-09-24 14:50:21 +02:00
|
|
|
}
|
2025-07-18 22:21:39 +08:00
|
|
|
|
|
|
|
|
// Model for a person stored in the server
|
2026-08-05 12:00:49 -07:00
|
|
|
@freezed
|
|
|
|
|
abstract class DriftPerson with _$DriftPerson {
|
|
|
|
|
const factory DriftPerson({
|
|
|
|
|
required String id,
|
|
|
|
|
required DateTime createdAt,
|
|
|
|
|
required DateTime updatedAt,
|
|
|
|
|
required String ownerId,
|
|
|
|
|
required String name,
|
2025-07-18 22:21:39 +08:00
|
|
|
String? faceAssetId,
|
2026-08-05 12:00:49 -07:00
|
|
|
required bool isFavorite,
|
|
|
|
|
required bool isHidden,
|
|
|
|
|
required String? color,
|
2025-07-18 22:21:39 +08:00
|
|
|
DateTime? birthDate,
|
2026-08-05 12:00:49 -07:00
|
|
|
}) = _DriftPerson;
|
2025-07-18 22:21:39 +08:00
|
|
|
}
|