import 'dart:collection';
import 'package:habo/constants.dart';
import 'package:habo/model/habo_model.dart';
import 'package:habo/repositories/event_repository.dart';

class SqliteEventRepository implements EventRepository {
  final HaboModel _model;

  SqliteEventRepository(this._model);

  @override
  Future<List<List>> getEventsForHabit(int habitId) async {
    return _model.getEventsForHabit(habitId);
  }

  @override
  Future<SplayTreeMap<DateTime, List>> getEventsMapForHabit(int habitId) async {
    return _model.getEventsMapForHabit(habitId);
  }

  @override
  Future<void> insertEvent(int habitId, DateTime date, List event) async {
    await _model.insertEvent(habitId, date, event);
  }

  @override
  Future<void> deleteEvent(int habitId, DateTime date) async {
    await _model.deleteEvent(habitId, date);
  }

  @override
  Future<void> deleteAllEventsForHabit(int habitId) async {
    await _model.deleteAllEventsForHabit(habitId);
  }

  @override
  Future<void> insertEventsForHabit(int habitId, Map<DateTime, List> events) async {
    for (final entry in events.entries) {
      await _model.insertEvent(habitId, entry.key, entry.value);
    }
  }

  @override
  Future<void> deleteAllEvents() async {
    await _model.deleteAllEvents();
  }
}
