Files
flux/lib/core/blocs/session/session_state.dart
2026-05-31 19:04:48 +02:00

86 lines
2.3 KiB
Dart

part of 'session_cubit.dart';
/// Definisce lo stato macroscopico della sessione
enum SessionStatus {
initial,
unauthenticated,
onboardingRequired,
authenticated,
error,
}
/// 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
}
class SessionState extends Equatable {
final SessionStatus status;
final User? user; // Utente di Supabase Auth
final CompanyModel? company;
final StoreModel? currentStore;
final StaffMemberModel? currentStaffMember;
final OnboardingStep onboardingStep;
final bool isMobileDevice;
final bool isSingleUserMode;
final String? errorMessage;
const SessionState({
this.status = SessionStatus.initial,
this.user,
this.company,
this.currentStore,
this.currentStaffMember,
this.onboardingStep = OnboardingStep.none,
this.isMobileDevice = false,
this.isSingleUserMode = false,
this.errorMessage,
});
/// Metodo per creare una copia dello stato modificando solo i campi necessari
SessionState copyWith({
SessionStatus? status,
User? user,
CompanyModel? company,
StoreModel? currentStore,
StaffMemberModel? currentStaffMember,
OnboardingStep? onboardingStep,
bool? isMobileDevice,
bool? isSingleUserMode,
String? errorMessage,
}) {
return SessionState(
status: status ?? this.status,
user: user ?? this.user,
company: company ?? this.company,
currentStore: currentStore ?? this.currentStore,
currentStaffMember: currentStaffMember ?? this.currentStaffMember,
onboardingStep: onboardingStep ?? this.onboardingStep,
isMobileDevice: isMobileDevice ?? this.isMobileDevice,
isSingleUserMode: isSingleUserMode ?? this.isSingleUserMode,
errorMessage: errorMessage ?? this.errorMessage,
);
}
@override
List<Object?> get props => [
status,
user,
company,
currentStore,
currentStaffMember,
onboardingStep,
isMobileDevice,
isSingleUserMode,
errorMessage,
];
// Helper rapidi per la UI
bool get isAuthenticated => status == SessionStatus.authenticated;
bool get needsOnboarding => status == SessionStatus.onboardingRequired;
}