package com.alexstyl.specialdates.events.peopleevents;

import android.content.Context;

import com.alexstyl.specialdates.contact.ContactsProvider;
import com.alexstyl.specialdates.events.database.EventSQLiteOpenHelper;
import com.alexstyl.specialdates.events.namedays.NamedayDatabaseRefresher;
import com.alexstyl.specialdates.events.namedays.NamedayPreferences;
import com.alexstyl.specialdates.events.namedays.calendar.resource.NamedayCalendarProvider;
import com.alexstyl.specialdates.util.DateParser;

import static com.alexstyl.specialdates.contact.ContactSource.SOURCE_DEVICE;

public class DebugPeopleEventsUpdater {

    private final DeviceEventsDatabaseRefresher deviceEventsDatabaseRefresher;
    private final NamedayDatabaseRefresher namedayDatabaseRefresher;

    public static DebugPeopleEventsUpdater newInstance(Context context) {
        ContactsProvider contactsProvider = ContactsProvider.get(context);
        AndroidEventsRepository repository = new AndroidEventsRepository(context.getContentResolver(), contactsProvider, DateParser.INSTANCE);
        ContactEventsMarshaller deviceMarshaller = new ContactEventsMarshaller(SOURCE_DEVICE);
        PeopleEventsPersister databaseProvider = new PeopleEventsPersister(new EventSQLiteOpenHelper(context));

        DeviceEventsDatabaseRefresher databaseRefresher = new DeviceEventsDatabaseRefresher(repository, deviceMarshaller, databaseProvider);

        NamedayPreferences namedayPreferences = NamedayPreferences.newInstance(context);
        NamedayCalendarProvider namedayCalendarProvider = NamedayCalendarProvider.newInstance(context.getResources());
        PeopleNamedaysCalculator peopleNamedaysCalculator = new PeopleNamedaysCalculator(namedayPreferences, namedayCalendarProvider, contactsProvider);
        return new DebugPeopleEventsUpdater(databaseRefresher, new NamedayDatabaseRefresher(
                namedayPreferences,
                databaseProvider,
                deviceMarshaller,
                peopleNamedaysCalculator
        ));
    }

    private DebugPeopleEventsUpdater(DeviceEventsDatabaseRefresher deviceEventsDatabaseRefresher, NamedayDatabaseRefresher namedayDatabaseRefresher) {
        this.deviceEventsDatabaseRefresher = deviceEventsDatabaseRefresher;
        this.namedayDatabaseRefresher = namedayDatabaseRefresher;
    }

    public void refresh() {
        deviceEventsDatabaseRefresher.rebuildEvents();
        namedayDatabaseRefresher.refreshNamedaysIfEnabled();
    }
}

@@ -585,16 +585,22 @@
 %0Apublic 
+final 
 class De
@@ -1713,16 +1713,33 @@
 culator(
+%0A                
 namedayP
@@ -1749,16 +1749,32 @@
 erences,
+%0A               
  nameday
@@ -1790,16 +1790,32 @@
 rovider,
+%0A               
  contact
@@ -1823,16 +1823,25 @@
 Provider
+%0A        
 );%0A     

Make class final and break long line