import 'dart:async';

import 'package:todos_repository_core/todos_repository_core.dart';

/// A class that is meant to represent a Client that would be used to call a Web
/// Service. It is responsible for fetching and persisting Todos to and from the
/// cloud.
///
/// Since we're trying to keep this example simple, it doesn't communicate with
/// a real server but simply emulates the functionality.
class WebClient implements TodosRepository {
  final Duration delay;

  const WebClient([this.delay = const Duration(milliseconds: 3000)]);

  /// Mock that "fetches" some Todos from a "web service" after a short delay
  @override
  Future<List<TodoEntity>> loadTodos() async {
    return Future.delayed(
        delay,
        () => [
              TodoEntity(
                'Buy food for da kitty',
                '1',
                'With the chickeny bits!',
                false,
              ),
              TodoEntity(
                'Find a Red Sea dive trip',
                '2',
                'Echo vs MY Dream',
                false,
              ),
              TodoEntity(
                'Book flights to Egypt',
                '3',
                '',
                true,
              ),
              TodoEntity(
                'Decide on accommodation',
                '4',
                '',
                false,
              ),
              TodoEntity(
                'Sip Margaritas',
                '5',
                'on the beach',
                true,
              ),
            ]);
  }

  /// Mock that returns true or false for success or failure. In this case,
  /// it will "Always Succeed"
  @override
  Future<bool> saveTodos(List<TodoEntity> todos) async {
    return Future.value(true);
  }
}
