Files
Client/lib/state/app/modules/capabilities/bloc/capabilities_state.dart
T

41 lines
1.6 KiB
Dart

import 'package:freezed_annotation/freezed_annotation.dart';
import '../../../../../access/user_role.dart';
import '../../../../../api/marianumconnect/queries/get_capabilities/guardian_child.dart';
part 'capabilities_state.freezed.dart';
part 'capabilities_state.g.dart';
@freezed
abstract class CapabilitiesState with _$CapabilitiesState {
const CapabilitiesState._();
const factory CapabilitiesState({
@Default(false) bool viewForeignTimetables,
@Default(false) bool pushNotifications,
// Days into the past/future the timetable may be scrolled. Null = no
// client-side clamp; the (server-narrowed) school year alone governs.
int? timetablePastDays,
int? timetableFutureDays,
// Wire value of the user type; read it through [role].
String? userType,
// Students a guardian may see; empty for all other accounts.
@Default(<GuardianChild>[]) List<GuardianChild> children,
// Whether a capability response (or a definitive failure) has been
// observed at least once this session. Lets the UI distinguish "still
// unknown" from "confirmed not allowed".
@Default(false) bool loaded,
// True while the last attempt failed. Not persisted: a stale failure from
// the previous run must not colour a fresh start. Together with [loaded]
// it separates "confirmed no children" from "could not ask".
@JsonKey(includeToJson: false, includeFromJson: false)
@Default(false)
bool loadFailed,
}) = _CapabilitiesState;
factory CapabilitiesState.fromJson(Map<String, Object?> json) =>
_$CapabilitiesStateFromJson(json);
UserRole get role => UserRole.parse(userType);
}