2026-04-22 11:06:02 +02:00
|
|
|
part of 'session_cubit.dart';
|
2026-04-06 10:55:56 +02:00
|
|
|
|
2026-04-22 11:06:02 +02:00
|
|
|
/// Definisce lo stato macroscopico della sessione
|
2026-04-06 10:55:56 +02:00
|
|
|
enum SessionStatus {
|
2026-04-22 11:06:02 +02:00
|
|
|
initial,
|
2026-04-06 10:55:56 +02:00
|
|
|
unauthenticated,
|
2026-04-22 11:06:02 +02:00
|
|
|
onboardingRequired,
|
|
|
|
|
authenticated,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Definisce lo step esatto dell'onboarding (Paranoia Mode)
|
|
|
|
|
enum OnboardingStep {
|
|
|
|
|
none, // Non serve onboarding
|
|
|
|
|
company, // Step 1: Manca l'azienda
|
|
|
|
|
store, // Step 2: Manca il negozio
|
|
|
|
|
staff, // Step 3: Manca il profilo staff ("Paziente Zero")
|
|
|
|
|
completed, // Flusso terminato con successo
|
2026-04-06 10:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SessionState extends Equatable {
|
|
|
|
|
final SessionStatus status;
|
2026-04-22 11:06:02 +02:00
|
|
|
final User? user; // Utente di Supabase Auth
|
2026-04-09 16:01:57 +02:00
|
|
|
final CompanyModel? company;
|
2026-04-22 11:06:02 +02:00
|
|
|
final StoreModel? currentStore;
|
|
|
|
|
final StaffMemberModel? currentStaff;
|
|
|
|
|
final OnboardingStep onboardingStep;
|
2026-04-06 10:55:56 +02:00
|
|
|
|
2026-04-09 16:01:57 +02:00
|
|
|
const SessionState({
|
2026-04-22 11:06:02 +02:00
|
|
|
this.status = SessionStatus.initial,
|
|
|
|
|
this.user,
|
2026-04-09 16:01:57 +02:00
|
|
|
this.company,
|
2026-04-22 11:06:02 +02:00
|
|
|
this.currentStore,
|
|
|
|
|
this.currentStaff,
|
|
|
|
|
this.onboardingStep = OnboardingStep.none,
|
2026-04-06 10:55:56 +02:00
|
|
|
});
|
|
|
|
|
|
2026-04-22 11:06:02 +02:00
|
|
|
/// Metodo per creare una copia dello stato modificando solo i campi necessari
|
2026-04-09 16:01:57 +02:00
|
|
|
SessionState copyWith({
|
|
|
|
|
SessionStatus? status,
|
2026-04-22 11:06:02 +02:00
|
|
|
User? user,
|
2026-04-09 16:01:57 +02:00
|
|
|
CompanyModel? company,
|
2026-04-22 11:06:02 +02:00
|
|
|
StoreModel? currentStore,
|
|
|
|
|
StaffMemberModel? currentStaff,
|
|
|
|
|
OnboardingStep? onboardingStep,
|
2026-04-09 16:01:57 +02:00
|
|
|
}) {
|
|
|
|
|
return SessionState(
|
|
|
|
|
status: status ?? this.status,
|
2026-04-22 11:06:02 +02:00
|
|
|
user: user ?? this.user,
|
2026-04-09 16:01:57 +02:00
|
|
|
company: company ?? this.company,
|
2026-04-22 11:06:02 +02:00
|
|
|
currentStore: currentStore ?? this.currentStore,
|
|
|
|
|
currentStaff: currentStaff ?? this.currentStaff,
|
|
|
|
|
onboardingStep: onboardingStep ?? this.onboardingStep,
|
2026-04-09 16:01:57 +02:00
|
|
|
);
|
|
|
|
|
}
|
2026-04-22 11:06:02 +02:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
List<Object?> get props => [
|
|
|
|
|
status,
|
|
|
|
|
user,
|
|
|
|
|
company,
|
|
|
|
|
currentStore,
|
|
|
|
|
currentStaff,
|
|
|
|
|
onboardingStep,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Helper rapidi per la UI
|
|
|
|
|
bool get isAuthenticated => status == SessionStatus.authenticated;
|
|
|
|
|
bool get needsOnboarding => status == SessionStatus.onboardingRequired;
|
2026-04-06 10:55:56 +02:00
|
|
|
}
|