Préremplit parents, enfants, motivation et fiche AM depuis reprise-dossier et envoie le body PATCH complet (co-parent, enfants par id, champs pro AM). Co-authored-by: Cursor <cursoragent@cursor.com>
232 lines
6.7 KiB
Dart
232 lines
6.7 KiB
Dart
import 'dart:io'; // Pour File
|
||
import '../models/card_assets.dart'; // Import de l'enum CardColorVertical
|
||
import 'package:flutter/foundation.dart';
|
||
// import 'package:p_tits_pas/models/child.dart'; // Commenté car fichier non trouvé
|
||
|
||
class ParentData {
|
||
String firstName;
|
||
String lastName;
|
||
String address; // Rue et numéro
|
||
String postalCode; // Ajout
|
||
String city; // Ajout
|
||
String phone;
|
||
String email;
|
||
String password; // Peut-être pas nécessaire pour le récap, mais pour la création initiale si
|
||
File? profilePicture; // Chemin ou objet File
|
||
|
||
ParentData({
|
||
this.firstName = '',
|
||
this.lastName = '',
|
||
this.address = '', // Rue
|
||
this.postalCode = '', // Ajout
|
||
this.city = '', // Ajout
|
||
this.phone = '',
|
||
this.email = '',
|
||
this.password = '',
|
||
this.profilePicture,
|
||
});
|
||
}
|
||
|
||
class ChildData {
|
||
static const Object _unsetImage = Object();
|
||
static const Object _unsetImageBytes = Object();
|
||
|
||
String firstName;
|
||
String lastName;
|
||
String dob; // Date de naissance ou prévisionnelle
|
||
/// Valeurs API : `H`, `F`, `Autre` (GenreType backend). Vide tant que non choisi.
|
||
String genre;
|
||
bool photoConsent;
|
||
bool multipleBirth;
|
||
bool isUnbornChild;
|
||
File? imageFile;
|
||
/// Octets de la photo (fiable à l’envoi API ; [imageFile] peut être absent sur le web).
|
||
Uint8List? imageBytes;
|
||
CardColorVertical cardColor; // Nouveau champ pour la couleur de la carte
|
||
/// UUID enfant en base (reprise #112) — requis pour PATCH reprise-resoumettre.
|
||
String? repriseChildId;
|
||
/// Photo déjà stockée (affichage reprise sans re-upload).
|
||
String? existingPhotoUrl;
|
||
|
||
ChildData({
|
||
this.firstName = '',
|
||
this.lastName = '',
|
||
this.dob = '',
|
||
this.genre = '',
|
||
this.photoConsent = false,
|
||
this.multipleBirth = false,
|
||
this.isUnbornChild = false,
|
||
this.imageFile,
|
||
this.imageBytes,
|
||
required this.cardColor, // Rendre requis dans le constructeur
|
||
this.repriseChildId,
|
||
this.existingPhotoUrl,
|
||
});
|
||
|
||
ChildData copyWith({
|
||
String? firstName,
|
||
String? lastName,
|
||
String? dob,
|
||
String? genre,
|
||
bool? photoConsent,
|
||
bool? multipleBirth,
|
||
bool? isUnbornChild,
|
||
Object? imageFile = _unsetImage,
|
||
Object? imageBytes = _unsetImageBytes,
|
||
CardColorVertical? cardColor,
|
||
String? repriseChildId,
|
||
String? existingPhotoUrl,
|
||
}) {
|
||
return ChildData(
|
||
firstName: firstName ?? this.firstName,
|
||
lastName: lastName ?? this.lastName,
|
||
dob: dob ?? this.dob,
|
||
genre: genre ?? this.genre,
|
||
photoConsent: photoConsent ?? this.photoConsent,
|
||
multipleBirth: multipleBirth ?? this.multipleBirth,
|
||
isUnbornChild: isUnbornChild ?? this.isUnbornChild,
|
||
imageFile: identical(imageFile, _unsetImage) ? this.imageFile : imageFile as File?,
|
||
imageBytes:
|
||
identical(imageBytes, _unsetImageBytes) ? this.imageBytes : imageBytes as Uint8List?,
|
||
cardColor: cardColor ?? this.cardColor,
|
||
repriseChildId: repriseChildId ?? this.repriseChildId,
|
||
existingPhotoUrl: existingPhotoUrl ?? this.existingPhotoUrl,
|
||
);
|
||
}
|
||
}
|
||
|
||
// Nouvelle classe pour les détails bancaires
|
||
class BankDetails {
|
||
String bankName;
|
||
String iban;
|
||
String bic;
|
||
|
||
BankDetails({
|
||
this.bankName = '',
|
||
this.iban = '',
|
||
this.bic = '',
|
||
});
|
||
}
|
||
|
||
class UserRegistrationData extends ChangeNotifier {
|
||
ParentData parent1;
|
||
ParentData? parent2; // Optionnel
|
||
List<ChildData> children;
|
||
String motivationText;
|
||
bool cguAccepted;
|
||
BankDetails? bankDetails; // Ajouté
|
||
String attestationCafNumber; // Ajouté
|
||
bool consentQuotientFamilial; // Ajouté
|
||
|
||
UserRegistrationData({
|
||
ParentData? parent1Data,
|
||
this.parent2,
|
||
List<ChildData>? childrenData,
|
||
this.motivationText = '',
|
||
this.cguAccepted = false,
|
||
this.bankDetails, // Ajouté
|
||
this.attestationCafNumber = '', // Ajouté
|
||
this.consentQuotientFamilial = false, // Ajouté
|
||
}) : parent1 = parent1Data ?? ParentData(),
|
||
children = childrenData ?? [];
|
||
|
||
// Méthode pour ajouter/mettre à jour le parent 1
|
||
void updateParent1(ParentData data) {
|
||
parent1 = data;
|
||
notifyListeners(); // Notifier les changements
|
||
}
|
||
|
||
// Méthode pour ajouter/mettre à jour le parent 2
|
||
void updateParent2(ParentData? data) {
|
||
parent2 = data;
|
||
notifyListeners();
|
||
}
|
||
|
||
// Méthode pour ajouter un enfant
|
||
void addChild(ChildData child) {
|
||
children.add(child);
|
||
notifyListeners();
|
||
}
|
||
|
||
// Méthode pour mettre à jour un enfant (si nécessaire plus tard)
|
||
void updateChild(int index, ChildData child) {
|
||
if (index >= 0 && index < children.length) {
|
||
children[index] = child;
|
||
notifyListeners();
|
||
}
|
||
}
|
||
|
||
// Méthode pour supprimer un enfant
|
||
void removeChild(int index) {
|
||
if (index >= 0 && index < children.length) {
|
||
children.removeAt(index);
|
||
notifyListeners();
|
||
}
|
||
}
|
||
|
||
// Mettre à jour la motivation
|
||
void updateMotivation(String text) {
|
||
motivationText = text;
|
||
notifyListeners();
|
||
}
|
||
|
||
// Mettre à jour les informations bancaires et CAF
|
||
void updateFinancialInfo({
|
||
BankDetails? bankDetails,
|
||
String? attestationCafNumber,
|
||
bool? consentQuotientFamilial,
|
||
}) {
|
||
if (bankDetails != null) this.bankDetails = bankDetails;
|
||
if (attestationCafNumber != null) this.attestationCafNumber = attestationCafNumber;
|
||
if (consentQuotientFamilial != null) this.consentQuotientFamilial = consentQuotientFamilial;
|
||
notifyListeners();
|
||
}
|
||
|
||
// Accepter les CGU
|
||
void acceptCGU(bool accepted) { // Prend un booléen
|
||
cguAccepted = accepted;
|
||
notifyListeners();
|
||
}
|
||
|
||
/// Reprise après refus (#112) : réinitialise le flux parent avec les données dossier.
|
||
void resetForReprise({
|
||
required ParentData parent1Data,
|
||
ParentData? parent2Data,
|
||
List<ChildData>? childrenData,
|
||
String motivation = '',
|
||
}) {
|
||
parent1 = parent1Data;
|
||
parent2 = parent2Data;
|
||
children
|
||
..clear()
|
||
..addAll(childrenData ?? const []);
|
||
motivationText = motivation;
|
||
cguAccepted = false;
|
||
bankDetails = null;
|
||
attestationCafNumber = '';
|
||
consentQuotientFamilial = false;
|
||
notifyListeners();
|
||
}
|
||
|
||
/// Reprise (#112) : coordonnées + enfants connus + CGU.
|
||
bool get isRepriseSubmitReady =>
|
||
parent1.firstName.isNotEmpty &&
|
||
parent1.lastName.isNotEmpty &&
|
||
parent1.email.isNotEmpty &&
|
||
children.isNotEmpty &&
|
||
children.every(
|
||
(c) =>
|
||
c.repriseChildId != null && c.repriseChildId!.trim().isNotEmpty,
|
||
) &&
|
||
cguAccepted;
|
||
|
||
// Méthode pour vérifier si toutes les données requises sont là (simplifié)
|
||
bool isRegistrationComplete() {
|
||
// Ajouter ici les validations nécessaires
|
||
// Exemple : parent1 doit avoir des champs remplis, au moins un enfant, CGU acceptées
|
||
return parent1.firstName.isNotEmpty &&
|
||
parent1.lastName.isNotEmpty &&
|
||
children.isNotEmpty &&
|
||
cguAccepted;
|
||
}
|
||
} |