import 'package:mc_gallery/features/core/services/logging_service.dart'; import 'package:mc_gallery/features/home/data/models/image_model.dart'; import 'package:mc_gallery/locator.dart'; import '../abstracts/images_api.dart'; /// Handles fetching and storing of Images. /// /// Since this is very simple use-case, this is the only interface. For complex (actual CRUD-based) I/O, /// an additional Repository layer interface can be used between [ImagesService] and [ImagesApi]. class ImagesService { ImagesService({ required ImagesApi imagesApi, required LoggingService loggingService, }) : _imagesApi = imagesApi, _loggingService = loggingService { _init(); } final ImagesApi _imagesApi; final LoggingService _loggingService; late final Iterable _imageModels; Iterable get imageModels => _imageModels; Future _init() async { _loggingService.info('Fetching and creating image models...'); _imageModels = await _imagesApi.fetchImageUri(token: ''); _imageModels.isNotEmpty ? _loggingService.good("Created ${_imageModels.length} images' models") : _loggingService.warning('No images found'); Locator.instance().signalReady(this); } int get firstAvailableImageIndex => 0; int get lastAvailableImageIndex => _imageModels.length - 1; static ImagesService get locate => Locator.locate(); }