class TenantSession { const TenantSession({ required this.baseUrl, required this.token, this.companyName, this.ruc, this.userType, this.activeEstablishmentId, this.moduleValues, this.annularPurchase = true, this.editPurchase = true, this.deletePurchase = true, this.annularSale = true, this.editPaymentMethod = false, }); final String baseUrl; final String token; final String? companyName; final String? ruc; /// Role del usuario: 'admin', 'seller', 'integrator'. Null si desconocido. final String? userType; final int? activeEstablishmentId; /// Modulos habilitados para el usuario (mismos `value` que usa el sidebar /// web: 'documents', 'purchases', 'items', 'persons', 'inventory', /// 'reports', 'pos', 'dashboard'...). Null = sesion vieja sin refrescar /// (antes de este campo) -> se trata igual que "todos habilitados", igual /// que hace la web cuando el usuario no tiene ninguna fila en module_user. final List? moduleValues; /// Permisos por funcion (columnas `users.*` en la web). Los defaults /// (true/true/true/true/false) replican el default de esas columnas en la /// base de datos, para que una sesion vieja sin este campo no pierda /// acceso hasta el proximo login. final bool annularPurchase; final bool editPurchase; final bool deletePurchase; final bool annularSale; final bool editPaymentMethod; bool get isSeller => userType == 'seller'; bool get isAdmin => userType == 'admin' || userType == null; /// true si el usuario tiene el modulo, o si no hay lista (sesion vieja o /// usuario sin modulos asignados = "todos", mismo criterio que la web). bool hasModule(String value) { final modules = moduleValues; if (modules == null || modules.isEmpty) return true; return modules.contains(value); } }