import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/list_files/cacheable_file.dart';
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/list_files/list_files_response.dart';

void main() {
  group('ListFilesResponse cache round-trip', () {
    test('isSharedWithMe survives jsonEncode -> decode -> fromJson', () {
      final response = ListFilesResponse({
        CacheableFile(
          path: 'Shared/',
          isDirectory: true,
          name: 'Shared',
          isSharedWithMe: true,
        ),
        CacheableFile(
          path: 'own.txt',
          isDirectory: false,
          name: 'own.txt',
        ),
      });

      // Mirror exactly what RequestCache does: jsonEncode the response, then
      // read it back through fromJson.
      final encoded = jsonEncode(response);
      final decoded = ListFilesResponse.fromJson(
        jsonDecode(encoded) as Map<String, dynamic>,
      );

      final shared = decoded.files.firstWhere((f) => f.name == 'Shared');
      final own = decoded.files.firstWhere((f) => f.name == 'own.txt');

      expect(shared.isSharedWithMe, isTrue);
      expect(own.isSharedWithMe, isNull);
    });
  });
}
