package com.alexstyl.specialdates.events;

import android.content.ContentValues;

import com.alexstyl.specialdates.Marshaller;
import com.alexstyl.specialdates.contact.Contact;
import com.alexstyl.specialdates.date.ContactEvent;
import com.alexstyl.specialdates.date.DateDisplayStringCreator;

import java.util.List;

public class ContactEventsMarshaller implements Marshaller<List<ContactEvent>> {

    @Override
    public ContentValues[] marshall(List<ContactEvent> item) {
        ContentValues[] returningValues = new ContentValues[item.size()];
        for (int i = 0; i < item.size(); i++) {
            ContactEvent event = item.get(i);
            returningValues[i] = createValuesFor(event);
        }
        return returningValues;
    }

    private ContentValues createValuesFor(ContactEvent event) {
        Contact contact = event.getContact();

        ContentValues values = new ContentValues(4);
        values.put(PeopleEventsContract.PeopleEvents.CONTACT_ID, contact.getContactID());
        values.put(PeopleEventsContract.PeopleEvents.SOURCE, ContactSource.DEVICE);
        values.put(PeopleEventsContract.PeopleEvents.DISPLAY_NAME, contact.getDisplayName().toString());

        String date = DateDisplayStringCreator.getInstance().stringOf(event.getDate());
        values.put(PeopleEventsContract.PeopleEvents.DATE, date);

        values.put(PeopleEventsContract.PeopleEvents.EVENT_TYPE, PeopleEventsContract.PeopleEvents.TYPE_NAMEDAY);
        return values;
    }
}

@@ -285,16 +285,67 @@
 Creator;
+%0Aimport com.novoda.notils.exception.DeveloperError;
 %0A%0Aimport
@@ -1463,56 +1463,245 @@
 PE, 
-PeopleEvents
+getTypeFor(event));%0A        return values;%0A    %7D%0A%0A    private int getTypeFor(
 Cont
-r
 act
-.PeopleEvents.TYPE_
+Event event) %7B%0A        switch (event.getType()) %7B%0A            case BIRTHDAY:%0A                return EventColumns.TYPE_BIRTHDAY;%0A            case 
 NAMEDAY
-);
+:
 %0A   
@@ -1705,31 +1705,153 @@
         
-return values
+        return EventColumns.TYPE_NAMEDAY;%0A        %7D%0A        throw new DeveloperError(event.getType() + %22 has no EventColumn reference%22)
 ;%0A    %7D%0A
 %7D%0A
@@ -1848,10 +1848,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Create specific type for each event type