/**
 * Copyright (C) 2012 - Florindo Smilari (spherIC)
 */
package ch.spherIC.recurvebowsight.database.dao;

import android.content.ContentValues;

import android.database.Cursor;

import ch.spherIC.recurvebowsight.database.scheme.masterdata.TblRBSRiser;
import ch.spherIC.recurvebowsight.model.IRiser;
import ch.spherIC.recurvebowsight.model.Riser;


/**
 * @author  FC Smilari
 */
public final class RiserDao extends DAO<IRiser> {


    private static RiserDao instance;

    private RiserDao() {
        super();
    }

    public static RiserDao getInstance() {
        if (instance == null) {
            instance = new RiserDao();
        }
        return instance;
    }


    @Override
    protected IRiser cursorToEntity(final Cursor cursor) {
        IRiser riser = new Riser(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getDouble(3), cursor.getDouble(4),
                                 cursor.getDouble(5));
        return riser;
    }

    @Override
    protected ContentValues getContentValues(final IRiser entity) {
        ContentValues values = new ContentValues();

        if (entity.getId() > 0) {
            values.put(TblRBSRiser.COL_ID, entity.getId());
        }

        values.put(TblRBSRiser.COL_MANUFACTURER, !entity.getManufacturer().isEmpty() ? entity.getManufacturer() : "");
        values.put(TblRBSRiser.COL_MODEL, !entity.getModel().isEmpty() ? entity.getModel() : "");
        values.put(TblRBSRiser.COL_SIZE, entity.getSize() != null ? entity.getSize() : 0d);
        values.put(TblRBSRiser.COL_VVIS_H, entity.getVVisH() != null ? entity.getVVisH() : 0d);
        values.put(TblRBSRiser.COL_VVIS_V, entity.getVVisV() != null ? entity.getVVisV() : 0d);
        return values;
    }

    @Override
    protected String getTableName() {
        return TblRBSRiser.NAME;
    }

    @Override
    protected String getIdColumn() {
        return TblRBSRiser.COL_ID;
    }

    @Override
    protected String getOrderBy() {
        return TblRBSRiser.COL_MANUFACTURER + " asc, " + TblRBSRiser.COL_MODEL + " asc, " + TblRBSRiser.COL_SIZE + " asc";
    }
}
