import '../../marianumconnect/queries/parent_letters/parent_letter_models.dart'; import '../demo_persona.dart'; /// Demo inbox of the guardian persona: one letter per variant (information, /// acknowledgement, choice, signature, answered, expired, thread, attachment). /// Child ids match [DemoCapabilities.guardianState]. class DemoParentLetters { const DemoParentLetters._(); static const _lena = 'demo-child-1'; static const _jonas = 'demo-child-2'; static final Set _readInSession = {}; static void markRead(String letterId) => _readInSession.add(letterId); static ParentLetterListResponse list() { final items = [for (final letter in _letters()) letter.summary]; return ParentLetterListResponse( items: items, unreadCount: items.where((letter) => !letter.read).length, openCount: items .where((letter) => letter.status == ParentLetterStatus.open) .length, ); } static ParentLetterDetail detail(String letterId) { final letters = _letters(); return letters.firstWhere( (letter) => letter.summary.id == letterId, orElse: () => letters.first, ); } static ParentLetterPerson _teacher(int index) => ParentLetterPerson(displayName: DemoPersona.teachers[index].name); static const _participation = ParentLetterField( id: 'participation', type: ParentLetterFieldType.singleChoice, label: 'Nimmt Ihr Kind teil?', isRequired: true, options: [ ParentLetterOption(id: 'yes', label: 'Ja'), ParentLetterOption(id: 'no', label: 'Nein'), ], ); static List _letters() { final now = DateTime.now(); ParentLetterDetail letter({ required String id, required String subject, required ParentLetterPerson sender, required Duration age, required String body, required List childIds, bool read = true, ParentLetterStatus status = ParentLetterStatus.info, ParentLetterRequest? request, List children = const [], List attachments = const [], ParentLetterThread thread = const ParentLetterThread(enabled: true), }) => ParentLetterDetail( summary: ParentLetterSummary( id: id, subject: subject, preview: body.replaceAll('\n', ' ').trim(), sender: sender, sentAt: now.subtract(age), read: read || _readInSession.contains(id), childIds: childIds, attachmentCount: attachments.length, status: status, deadline: request?.deadline, ), content: ParentLetterContent( body: body, attachments: attachments, request: request, children: children, thread: thread, ), ); return [ letter( id: 'demo-letter-hike', subject: 'Wandertag der ${DemoPersona.className}', sender: _teacher(0), age: const Duration(hours: 2), read: false, childIds: const [_lena], status: ParentLetterStatus.open, body: 'Liebe Eltern,\n\nam Freitag in zwei Wochen findet unser Wandertag ' 'statt. Wir fahren mit dem Bus in die Rhön und sind gegen 16 Uhr ' 'zurück. Alle Einzelheiten finden Sie im angehängten Schreiben.\n\n' 'Bitte geben Sie uns eine verbindliche Rückmeldung.\n\n' 'Viele Grüße\n${DemoPersona.teachers[0].name}', attachments: const [ ParentLetterAttachment( id: 'demo-attachment-hike', fileName: 'Wandertag.pdf', mimeType: 'application/pdf', size: 48211, ), ], request: ParentLetterRequest( fields: const [_participation], signatureRequired: true, deadline: now.add(const Duration(days: 10)), ), children: const [ ParentLetterChildState( childId: _lena, status: ParentLetterStatus.open, editable: true, ), ], ), letter( id: 'demo-letter-parents-evening', subject: 'Einladung zum Elternabend der 6a', sender: _teacher(1), age: const Duration(days: 1), read: false, childIds: const [_jonas], status: ParentLetterStatus.open, body: 'Liebe Eltern,\n\nhiermit lade ich Sie herzlich zum ersten ' 'Elternabend des Schuljahres ein. Wir treffen uns am kommenden ' 'Dienstag um 19 Uhr in Raum ${DemoPersona.rooms[0]}.\n\n' 'Bitte bestätigen Sie kurz den Erhalt dieser Einladung.', request: const ParentLetterRequest(), children: const [ ParentLetterChildState( childId: _jonas, status: ParentLetterStatus.open, editable: true, ), ], ), letter( id: 'demo-letter-school-festival', subject: 'Schulfest: Wer kommt mit?', sender: _teacher(5), age: const Duration(days: 3), childIds: const [_lena, _jonas], status: ParentLetterStatus.open, body: 'Liebe Eltern,\n\nfür die Planung unseres Schulfestes möchten wir ' 'wissen, welche Kinder teilnehmen. Die Angabe können Sie bis zum ' 'Ablauf der Frist noch ändern.\n\nWeitere Informationen: ' 'https://www.marianum-fulda.de', request: ParentLetterRequest( fields: const [_participation], deadline: now.add(const Duration(days: 5)), ), children: [ ParentLetterChildState( childId: _lena, status: ParentLetterStatus.done, editable: true, response: ParentLetterResponse( respondedAt: now.subtract(const Duration(days: 2)), respondedBy: const ParentLetterPerson(self: true), answers: const [ ParentLetterAnswer( fieldId: 'participation', optionIds: ['yes'], ), ], ), ), const ParentLetterChildState( childId: _jonas, status: ParentLetterStatus.open, editable: true, ), ], ), letter( id: 'demo-letter-reports', subject: 'Zeugnisausgabe und Unterrichtsschluss', sender: _teacher(3), age: const Duration(days: 7), childIds: const [_lena, _jonas], body: 'Liebe Eltern,\n\nam letzten Schultag vor den Ferien endet der ' 'Unterricht nach der dritten Stunde mit der Zeugnisausgabe. Die ' 'Busse fahren entsprechend früher.', thread: ParentLetterThread( enabled: true, messages: [ ParentLetterThreadMessage( id: 'demo-thread-1', author: const ParentLetterPerson(self: true), body: 'Gilt das auch für die Nachmittagsbetreuung?', sentAt: now.subtract(const Duration(days: 6, hours: 20)), ), ParentLetterThreadMessage( id: 'demo-thread-2', author: _teacher(3), body: 'Ja, die Betreuung entfällt an diesem Tag ebenfalls. Bei ' 'Bedarf melden Sie sich bitte im Sekretariat.', sentAt: now.subtract(const Duration(days: 6, hours: 2)), ), ], ), ), letter( id: 'demo-letter-swimming', subject: 'Einverständnis Schwimmunterricht', sender: _teacher(6), age: const Duration(days: 21), childIds: const [_jonas], status: ParentLetterStatus.done, body: 'Liebe Eltern,\n\nim zweiten Halbjahr findet der Sportunterricht ' 'der 6a im Hallenbad statt. Dafür benötigen wir Ihr ' 'Einverständnis.', request: const ParentLetterRequest( fields: [_participation], signatureRequired: true, ), children: [ ParentLetterChildState( childId: _jonas, status: ParentLetterStatus.done, response: ParentLetterResponse( respondedAt: now.subtract(const Duration(days: 20)), respondedBy: const ParentLetterPerson(displayName: 'M. Hoffmann'), answers: const [ ParentLetterAnswer( fieldId: 'participation', optionIds: ['yes'], ), ], signed: true, ), ), ], thread: const ParentLetterThread(), ), letter( id: 'demo-letter-ski-trip', subject: 'Anmeldung zur Skifreizeit', sender: _teacher(6), age: const Duration(days: 35), childIds: const [_lena], status: ParentLetterStatus.expired, body: 'Liebe Eltern,\n\ndie Anmeldung zur Skifreizeit der Jahrgangsstufe ' '10 ist ab sofort möglich. Die Plätze sind begrenzt.', request: ParentLetterRequest( fields: const [_participation], signatureRequired: true, deadline: now.subtract(const Duration(days: 14)), ), children: const [ ParentLetterChildState( childId: _lena, status: ParentLetterStatus.expired, ), ], thread: const ParentLetterThread(), ), ]; } }