// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:architecture_example/data/models/photo_model.dart';
import 'package:architecture_example/domain/data_sources/local/favorite_local_data_source.dart';
import 'package:architecture_example/domain/entities/photo.dart';

class FavoriteMockDataSource extends FavoriteLocalDataSource {
  final Map<int, Photo> _mock = {
    2: const PhotoModel(
      albumId: 1,
      id: 2,
      title: 'Photo 2',
      url: 'https://via.placeholder.com/600/771796',
      thumbnailUrl: 'https://via.placeholder.com/150/771796',
    ),
  };

  @override
  Future<void> addPhotoToFavorites(Photo photo) async {
    if (_mock.containsKey(photo.id)) {
      throw Exception('Photo already in favorites');
    }
    _mock.putIfAbsent(photo.id, () => photo);
  }

  @override
  Future<bool> checkIfPhotoIsInFavorites(int id) async => _mock.containsKey(id);

  @override
  Future<void> deletePhotoFromFavorites(int id) async {
    if (!_mock.containsKey(id)) {
      throw Exception('Unknown photo');
    }
    _mock.remove(id);
  }

  @override
  Future<List<int>> getAllPhotosFromFavorites() async {
    final result = _mock.keys;
    return result.toList();
  }
}
