import 'package:dio/dio.dart'; import 'package:eatvio_app/features/blog_post_create/repositories/blog_post_repository.dart'; import 'package:eatvio_app/features/blog_post_create/services/blog_post_service.dart'; import 'package:flutter_image_compress/flutter_image_compress.dart'; class FixtureBlogPostRepository extends BlogPostRepository { FixtureBlogPostRepository() : super(blogPostService: _NoopBlogPostService()); final List createPayloads = []; final List updatePayloads = []; final List deleteCalls = []; Duration createDelay = Duration.zero; Duration updateDelay = Duration.zero; Duration deleteDelay = Duration.zero; Object? createError; Object? updateError; Object? deleteError; @override Future createBlogPost(String? title, String? videoUrl, String? description, XFile? image) async { createPayloads.add( BlogPostCreatePayload( title: title, description: description, videoUrl: videoUrl, imageName: image?.name, ), ); if (createDelay > Duration.zero) { await Future.delayed(createDelay); } if (createError != null) { throw createError!; } } @override Future updateBlogPost(int id, String? title, String? videoUrl, String? description, XFile? image, String? oldImageUrl) async { updatePayloads.add( BlogPostUpdatePayload( id: id, title: title, description: description, videoUrl: videoUrl, imageName: image?.name, oldImageUrl: oldImageUrl, ), ); if (updateDelay > Duration.zero) { await Future.delayed(updateDelay); } if (updateError != null) { throw updateError!; } } @override Future deleteBlogPost(int id) async { deleteCalls.add(id); if (deleteDelay > Duration.zero) { await Future.delayed(deleteDelay); } if (deleteError != null) { throw deleteError!; } } } class BlogPostCreatePayload { BlogPostCreatePayload({ required this.title, required this.description, required this.videoUrl, required this.imageName, }); final String? title; final String? description; final String? videoUrl; final String? imageName; Map toJson() => { 'title': title, 'description_md': description, 'video_url': videoUrl, 'image_name': imageName, }; } class BlogPostUpdatePayload { BlogPostUpdatePayload({ required this.id, required this.title, required this.description, required this.videoUrl, required this.imageName, required this.oldImageUrl, }); final int id; final String? title; final String? description; final String? videoUrl; final String? imageName; final String? oldImageUrl; Map toJson() => { 'id': id, 'title': title, 'description_md': description, 'video_url': videoUrl, 'image_name': imageName, 'old_image_url': oldImageUrl, }; } class _NoopBlogPostService implements BlogPostService { @override Future createBlogPost({required FormData formData}) { throw UnimplementedError('Fixture overrides repository methods directly.'); } @override Future deleteBlogPost({required int id}) { throw UnimplementedError('Fixture overrides repository methods directly.'); } @override Future updateBlogPost({required int id, required FormData formData}) { throw UnimplementedError('Fixture overrides repository methods directly.'); } } class FeedReloadProbe { int loadRequests = 0; Future loadFeedBlogPostList() async { loadRequests += 1; } }