package com.tofly.data.sql.dao;

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

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.tofly.ghrq_route.module.emergencyHandle.domain.EmergencyOverData;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "DB_EMERGENCY_OVER_DATA".
*/
public class EmergencyOverDataDao extends AbstractDao<EmergencyOverData, String> {

    public static final String TABLENAME = "DB_EMERGENCY_OVER_DATA";

    /**
     * Properties of entity EmergencyOverData.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, String.class, "id", true, "ID");
        public final static Property IsOver = new Property(1, int.class, "isOver", false, "IS_OVER");
        public final static Property OverTime = new Property(2, String.class, "overTime", false, "OVER_TIME");
    }


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

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"DB_EMERGENCY_OVER_DATA\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL UNIQUE ," + // 0: id
                "\"IS_OVER\" INTEGER NOT NULL ," + // 1: isOver
                "\"OVER_TIME\" TEXT);"); // 2: overTime
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, EmergencyOverData entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
        stmt.bindLong(2, entity.getIsOver());
 
        String overTime = entity.getOverTime();
        if (overTime != null) {
            stmt.bindString(3, overTime);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, EmergencyOverData entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
        stmt.bindLong(2, entity.getIsOver());
 
        String overTime = entity.getOverTime();
        if (overTime != null) {
            stmt.bindString(3, overTime);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.getString(offset + 0);
    }    

    @Override
    public EmergencyOverData readEntity(Cursor cursor, int offset) {
        EmergencyOverData entity = new EmergencyOverData( //
            cursor.getString(offset + 0), // id
            cursor.getInt(offset + 1), // isOver
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // overTime
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, EmergencyOverData entity, int offset) {
        entity.setId(cursor.getString(offset + 0));
        entity.setIsOver(cursor.getInt(offset + 1));
        entity.setOverTime(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final String updateKeyAfterInsert(EmergencyOverData entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(EmergencyOverData entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(EmergencyOverData entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
