// 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/album_model.dart';
import 'package:architecture_example/domain/data_sources/remote/album_remote_data_source.dart';
import 'package:architecture_example/domain/entities/album.dart';
import 'package:wyatt_type_utils/wyatt_type_utils.dart';

class AlbumMockDataSourceImpl extends AlbumRemoteDataSource {
  final Map<int, Album> _mock = {
    1: const AlbumModel(
      id: 1,
      userId: 1,
      title: 'Album 1',
    )
  };

  @override
  Future<Album> getAlbum(int id) async {
    final response = _mock[id];
    if (response.isNull) {
      throw Exception('Unknown album');
    }
    return response!;
  }

  @override
  Future<List<Album>> getAllAlbums({int? start, int? limit}) async {
    final response = _mock.values;
    final nullableEnd = (limit != null) ? start ?? 0 + limit : null;
    return response.toList().sublist(start ?? 0, nullableEnd);
  }
}
