package com.expidev.gcmapp.db;

import android.content.ContentValues;
import android.database.Cursor;
import android.support.annotation.NonNull;

import com.expidev.gcmapp.model.Church;

import org.ccci.gto.android.common.db.AbstractMapper;

public class ChurchMapper extends AbstractMapper<Church> {
    @Override
    protected void mapField(@NonNull final ContentValues values, @NonNull final String field,
                            @NonNull final Church church) {
        switch (field) {
            case Contract.Church.COLUMN_ID:
                values.put(field, church.getId());
                break;
            case Contract.Church.COLUMN_MINISTRY_ID:
                values.put(field, church.getMinistryId());
                break;
            case Contract.Church.COLUMN_NAME:
                values.put(field, church.getName());
                break;
            case Contract.Church.COLUMN_CONTACT_NAME:
                values.put(field, church.getContactName());
                break;
            case Contract.Church.COLUMN_CONTACT_EMAIL:
                values.put(field, church.getContactEmail());
                break;
            case Contract.Church.COLUMN_LATITUDE:
                values.put(field, church.getLatitude());
                break;
            case Contract.Church.COLUMN_LONGITUDE:
                values.put(field, church.getLongitude());
                break;
            case Contract.Church.COLUMN_DEVELOPMENT:
                values.put(field, church.getDevelopment().id);
                break;
            case Contract.Church.COLUMN_SIZE:
                values.put(field, church.getSize());
                break;
            case Contract.Church.COLUMN_SECURITY:
                values.put(field, church.getSecurity());
                break;
            default:
                super.mapField(values, field, church);
                break;
        }
    }

    @NonNull
    @Override
    protected Church newObject(@NonNull final Cursor cursor) {
        return new Church();
    }

    @NonNull
    @Override
    public Church toObject(@NonNull final Cursor c) {
        final Church church = super.toObject(c);
        church.setId(getLong(c, Contract.Church.COLUMN_ID, Church.INVALID_ID));
        church.setName(getString(c, Contract.Church.COLUMN_NAME, null));
        church.setContactName(getString(c, Contract.Church.COLUMN_CONTACT_NAME, null));
        church.setContactEmail(getString(c, Contract.Church.COLUMN_CONTACT_EMAIL, null));
        church.setLatitude(getDouble(c, Contract.Church.COLUMN_LATITUDE));
        church.setLongitude(getDouble(c, Contract.Church.COLUMN_LONGITUDE));
        church.setDevelopment(getInt(c, Contract.Church.COLUMN_DEVELOPMENT, Church.Development.UNKNOWN.id));
        church.setSize(getInt(c, Contract.Church.COLUMN_SIZE, 0));
        church.setSecurity(getInt(c, Contract.Church.COLUMN_SECURITY, 2));
        return church;
    }
}

@@ -184,63 +184,8 @@
 h;%0A%0A
-import org.ccci.gto.android.common.db.AbstractMapper;%0A%0A
 publ
@@ -218,16 +218,12 @@
 nds 
-Abstract
+Base
 Mapp

fix parent class to fix lastSync persisting