69 lines
1.8 KiB
Dart
69 lines
1.8 KiB
Dart
/// Un client fidélité. Le [code] est ce qui est encodé dans son QR code :
|
|
/// scanner le QR permet de retrouver le compte.
|
|
class Client {
|
|
final String id; // id PocketBase
|
|
|
|
/// Code unique du compte (encodé dans le QR), ex : « FID-3F9K2A ».
|
|
final String code;
|
|
|
|
final String nom;
|
|
final String? prenom;
|
|
final String? telephone;
|
|
|
|
/// Solde de points courant (peut être fractionnaire, ex : 12,48).
|
|
final double points;
|
|
|
|
const Client({
|
|
required this.id,
|
|
required this.code,
|
|
required this.nom,
|
|
this.prenom,
|
|
this.telephone,
|
|
this.points = 0,
|
|
});
|
|
|
|
/// Nom complet affiché : « Prénom Nom » (ou juste le nom si pas de prénom).
|
|
String get nomComplet {
|
|
final p = (prenom ?? '').trim();
|
|
return p.isEmpty ? nom : '$p $nom';
|
|
}
|
|
|
|
/// Initiales pour l'avatar (ex : « Jean Dupont » → « JD »).
|
|
String get initiales {
|
|
final p = (prenom ?? '').trim();
|
|
final n = nom.trim();
|
|
final a = p.isNotEmpty ? p[0] : (n.isNotEmpty ? n[0] : '?');
|
|
final b = n.isNotEmpty ? n[0] : '';
|
|
return (a + b).toUpperCase();
|
|
}
|
|
|
|
Client copyWith({
|
|
String? id,
|
|
String? code,
|
|
String? nom,
|
|
String? prenom,
|
|
String? telephone,
|
|
double? points,
|
|
}) {
|
|
return Client(
|
|
id: id ?? this.id,
|
|
code: code ?? this.code,
|
|
nom: nom ?? this.nom,
|
|
prenom: prenom ?? this.prenom,
|
|
telephone: telephone ?? this.telephone,
|
|
points: points ?? this.points,
|
|
);
|
|
}
|
|
|
|
factory Client.fromMap(Map<String, dynamic> map) {
|
|
return Client(
|
|
id: map['id'].toString(),
|
|
code: (map['code'] as String?) ?? '',
|
|
nom: (map['nom'] as String?) ?? '',
|
|
prenom: map['prenom'] as String?,
|
|
telephone: map['telephone'] as String?,
|
|
points: (map['points'] as num?)?.toDouble() ?? 0,
|
|
);
|
|
}
|
|
}
|