package com.company.professor;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;

import com.company.professor.EncounterMethods;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "encounter_methods".
*/
public class EncounterMethodsDao extends AbstractDao<EncounterMethods, Long> {

    public static final String TABLENAME = "encounter_methods";

    /**
     * Properties of entity EncounterMethods.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Id = new Property(0, long.class, "Id", true, "id");
        public final static Property Identifier = new Property(1, String.class, "Identifier", false, "identifier");
        public final static Property Order = new Property(2, long.class, "Order", false, "order");
    };


    public EncounterMethodsDao(DaoConfig config) {
        super(config);
    }
    
    public EncounterMethodsDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"encounter_methods\" (" + //
                "\"id\" INTEGER PRIMARY KEY NOT NULL ," + // 0: Id
                "\"identifier\" TEXT NOT NULL ," + // 1: Identifier
                "\"order\" INTEGER NOT NULL );"); // 2: Order
        // Add Indexes
        db.execSQL("CREATE UNIQUE INDEX " + constraint + "IDX_encounter_methods_identifier ON encounter_methods" +
                " (\"identifier\");");
        db.execSQL("CREATE UNIQUE INDEX " + constraint + "IDX_encounter_methods_order ON encounter_methods" +
                " (\"order\");");
    }

    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"encounter_methods\"";
        db.execSQL(sql);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, EncounterMethods entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
        stmt.bindString(2, entity.getIdentifier());
        stmt.bindLong(3, entity.getOrder());
    }

    /** @inheritdoc */
    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 0);
    }    

    /** @inheritdoc */
    @Override
    public EncounterMethods readEntity(Cursor cursor, int offset) {
        EncounterMethods entity = new EncounterMethods( //
            cursor.getLong(offset + 0), // Id
            cursor.getString(offset + 1), // Identifier
            cursor.getLong(offset + 2) // Order
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, EncounterMethods entity, int offset) {
        entity.setId(cursor.getLong(offset + 0));
        entity.setIdentifier(cursor.getString(offset + 1));
        entity.setOrder(cursor.getLong(offset + 2));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(EncounterMethods entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(EncounterMethods entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
}
