package com.example.sleep.database.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.example.sleep.database.RecordBean;

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

    public static final String TABLENAME = "RECORD_BEAN";

    /**
     * Properties of entity RecordBean.<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 Date = new Property(1, String.class, "date", false, "DATE");
        public final static Property StartTime = new Property(2, String.class, "startTime", false, "START_TIME");
        public final static Property EndTime = new Property(3, String.class, "endTime", false, "END_TIME");
        public final static Property TotalTime = new Property(4, int.class, "totalTime", false, "TOTAL_TIME");
        public final static Property DrawChart = new Property(5, boolean.class, "drawChart", false, "DRAW_CHART");
        public final static Property DeepTime = new Property(6, int.class, "deepTime", false, "DEEP_TIME");
        public final static Property SwallowTime = new Property(7, int.class, "swallowTime", false, "SWALLOW_TIME");
        public final static Property AwakeTime = new Property(8, int.class, "awakeTime", false, "AWAKE_TIME");
        public final static Property SleepDetail = new Property(9, String.class, "sleepDetail", false, "SLEEP_DETAIL");
        public final static Property Valid = new Property(10, boolean.class, "valid", false, "VALID");
    }


    public RecordBeanDao(DaoConfig config) {
        super(config);
    }
    
    public RecordBeanDao(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 + "\"RECORD_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"DATE\" TEXT," + // 1: date
                "\"START_TIME\" TEXT," + // 2: startTime
                "\"END_TIME\" TEXT," + // 3: endTime
                "\"TOTAL_TIME\" INTEGER NOT NULL ," + // 4: totalTime
                "\"DRAW_CHART\" INTEGER NOT NULL ," + // 5: drawChart
                "\"DEEP_TIME\" INTEGER NOT NULL ," + // 6: deepTime
                "\"SWALLOW_TIME\" INTEGER NOT NULL ," + // 7: swallowTime
                "\"AWAKE_TIME\" INTEGER NOT NULL ," + // 8: awakeTime
                "\"SLEEP_DETAIL\" TEXT," + // 9: sleepDetail
                "\"VALID\" INTEGER NOT NULL );"); // 10: valid
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, RecordBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String date = entity.getDate();
        if (date != null) {
            stmt.bindString(2, date);
        }
 
        String startTime = entity.getStartTime();
        if (startTime != null) {
            stmt.bindString(3, startTime);
        }
 
        String endTime = entity.getEndTime();
        if (endTime != null) {
            stmt.bindString(4, endTime);
        }
        stmt.bindLong(5, entity.getTotalTime());
        stmt.bindLong(6, entity.getDrawChart() ? 1L: 0L);
        stmt.bindLong(7, entity.getDeepTime());
        stmt.bindLong(8, entity.getSwallowTime());
        stmt.bindLong(9, entity.getAwakeTime());
 
        String sleepDetail = entity.getSleepDetail();
        if (sleepDetail != null) {
            stmt.bindString(10, sleepDetail);
        }
        stmt.bindLong(11, entity.getValid() ? 1L: 0L);
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, RecordBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String date = entity.getDate();
        if (date != null) {
            stmt.bindString(2, date);
        }
 
        String startTime = entity.getStartTime();
        if (startTime != null) {
            stmt.bindString(3, startTime);
        }
 
        String endTime = entity.getEndTime();
        if (endTime != null) {
            stmt.bindString(4, endTime);
        }
        stmt.bindLong(5, entity.getTotalTime());
        stmt.bindLong(6, entity.getDrawChart() ? 1L: 0L);
        stmt.bindLong(7, entity.getDeepTime());
        stmt.bindLong(8, entity.getSwallowTime());
        stmt.bindLong(9, entity.getAwakeTime());
 
        String sleepDetail = entity.getSleepDetail();
        if (sleepDetail != null) {
            stmt.bindString(10, sleepDetail);
        }
        stmt.bindLong(11, entity.getValid() ? 1L: 0L);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public RecordBean readEntity(Cursor cursor, int offset) {
        RecordBean entity = new RecordBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // date
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // startTime
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // endTime
            cursor.getInt(offset + 4), // totalTime
            cursor.getShort(offset + 5) != 0, // drawChart
            cursor.getInt(offset + 6), // deepTime
            cursor.getInt(offset + 7), // swallowTime
            cursor.getInt(offset + 8), // awakeTime
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // sleepDetail
            cursor.getShort(offset + 10) != 0 // valid
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, RecordBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setDate(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setStartTime(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setEndTime(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setTotalTime(cursor.getInt(offset + 4));
        entity.setDrawChart(cursor.getShort(offset + 5) != 0);
        entity.setDeepTime(cursor.getInt(offset + 6));
        entity.setSwallowTime(cursor.getInt(offset + 7));
        entity.setAwakeTime(cursor.getInt(offset + 8));
        entity.setSleepDetail(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setValid(cursor.getShort(offset + 10) != 0);
     }
    
    @Override
    protected final Long updateKeyAfterInsert(RecordBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(RecordBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(RecordBean entity) {
        return entity.getId() != null;
    }

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