/**
 * 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.TblRBSSight;
import ch.spherIC.recurvebowsight.model.ISight;
import ch.spherIC.recurvebowsight.model.Sight;


/**
 * @author  FC Smilari
 */
public final class SightDao extends DAO<ISight> {


    private static SightDao instance;

    private SightDao() {
        super();
    }

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


    @Override
    protected ISight cursorToEntity(final Cursor cursor) {

        ISight sight = new Sight(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getDouble(3), //
                                 cursor.getDouble(4), cursor.getString(5), cursor.getDouble(6), cursor.getDouble(7));
        return sight;
    }

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

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

        values.put(TblRBSSight.COL_MANUFACTURER, !entity.getManufacturer().isEmpty() ? entity.getManufacturer() : "");
        values.put(TblRBSSight.COL_MODEL, !entity.getModel().isEmpty() ? entity.getModel() : "");
        values.put(TblRBSSight.COL_AV, entity.getAV() != null ? entity.getAV() : 0d);
        values.put(TblRBSSight.COL_AH, entity.getAH() != null ? entity.getAH() : 0d);
        values.put(TblRBSSight.COL_HEVIS, entity.getHeVis() != null ? entity.getHeVis() : "");
        values.put(TblRBSSight.COL_VERTSKALARANGE_MIN, entity.getVertSkalaRangeMin() != null ? entity.getVertSkalaRangeMin() : 0d);
        values.put(TblRBSSight.COL_VERTSKALARANGE_MAX, entity.getVertSkalaRangeMax() != null ? entity.getVertSkalaRangeMax() : 0d);

        return values;
    }

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

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

}
