package com.sunzee.db;

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

import com.sunzee.model.domain.CleaningBean;
import com.sunzee.model.domain.WarringBean;

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

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.

/**
 * DAO for table "CLEANING_BEAN".
*/
public class CleaningBeanDao extends AbstractDao<CleaningBean, Long> {

    public static final String TABLENAME = "CLEANING_BEAN";

    /**
     * Properties of entity WarringBean.<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 Time = new Property(1, long.class, "time", false, "TIME");
        public final static Property CleanCount = new Property(2, String.class, "cleanCount", false, "CLEANCOUNT");
        public final static Property InCount = new Property(3, String.class, "inCount", false, "INCOUNT");
        public final static Property OutCount = new Property(4, String.class, "outCount", false, "OUTCOUNT");
    }


    public CleaningBeanDao(DaoConfig config) {
        super(config);
    }

    public CleaningBeanDao(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 + "\"CLEANING_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"TIME\" INTEGER NOT NULL ," + // 1: time
                "\"CLEANCOUNT\" TEXT," +
                "\"INCOUNT\" TEXT," +
                "\"OUTCOUNT\" TEXT);");
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, CleaningBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getTime());
 
        String cleanCount = entity.getCleanCount();
        if (cleanCount != null) {
            stmt.bindString(3, cleanCount);
        }
 
        String inCount = entity.getInCount();
        if (inCount != null) {
            stmt.bindString(4, inCount);
        }

        String outCount = entity.getOutCount();
        if (outCount != null) {
            stmt.bindString(5, outCount);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, CleaningBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getTime());

        String cleanCount = entity.getCleanCount();
        if (cleanCount != null) {
            stmt.bindString(3, cleanCount);
        }

        String inCount = entity.getInCount();
        if (inCount != null) {
            stmt.bindString(4, inCount);
        }

        String outCount = entity.getOutCount();
        if (outCount != null) {
            stmt.bindString(5, outCount);
        }
    }

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

    @Override
    public CleaningBean readEntity(Cursor cursor, int offset) {
        CleaningBean entity = new CleaningBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getLong(offset + 1), // time
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // thingError
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // remark
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // remark
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, CleaningBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setTime(cursor.getLong(offset + 1));
        entity.setCleanCount(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setInCount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setOutCount(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(CleaningBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(CleaningBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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