package com.faceunity.greendao;

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.faceunity.entity.MagicPhotoEntity;

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

    public static final String TABLENAME = "MAGIC_PHOTO_ENTITY";

    /**
     * Properties of entity MagicPhotoEntity.<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 Width = new Property(1, int.class, "width", false, "WIDTH");
        public final static Property Height = new Property(2, int.class, "height", false, "HEIGHT");
        public final static Property GroupPointsStr = new Property(3, String.class, "groupPointsStr", false, "GROUP_POINTS_STR");
        public final static Property GroupTypeStr = new Property(4, String.class, "groupTypeStr", false, "GROUP_TYPE_STR");
        public final static Property ImagePath = new Property(5, String.class, "imagePath", false, "IMAGE_PATH");
    }


    public MagicPhotoEntityDao(DaoConfig config) {
        super(config);
    }
    
    public MagicPhotoEntityDao(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 + "\"MAGIC_PHOTO_ENTITY\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"WIDTH\" INTEGER NOT NULL ," + // 1: width
                "\"HEIGHT\" INTEGER NOT NULL ," + // 2: height
                "\"GROUP_POINTS_STR\" TEXT," + // 3: groupPointsStr
                "\"GROUP_TYPE_STR\" TEXT," + // 4: groupTypeStr
                "\"IMAGE_PATH\" TEXT);"); // 5: imagePath
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, MagicPhotoEntity entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getWidth());
        stmt.bindLong(3, entity.getHeight());
 
        String groupPointsStr = entity.getGroupPointsStr();
        if (groupPointsStr != null) {
            stmt.bindString(4, groupPointsStr);
        }
 
        String groupTypeStr = entity.getGroupTypeStr();
        if (groupTypeStr != null) {
            stmt.bindString(5, groupTypeStr);
        }
 
        String imagePath = entity.getImagePath();
        if (imagePath != null) {
            stmt.bindString(6, imagePath);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, MagicPhotoEntity entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getWidth());
        stmt.bindLong(3, entity.getHeight());
 
        String groupPointsStr = entity.getGroupPointsStr();
        if (groupPointsStr != null) {
            stmt.bindString(4, groupPointsStr);
        }
 
        String groupTypeStr = entity.getGroupTypeStr();
        if (groupTypeStr != null) {
            stmt.bindString(5, groupTypeStr);
        }
 
        String imagePath = entity.getImagePath();
        if (imagePath != null) {
            stmt.bindString(6, imagePath);
        }
    }

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

    @Override
    public MagicPhotoEntity readEntity(Cursor cursor, int offset) {
        MagicPhotoEntity entity = new MagicPhotoEntity( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getInt(offset + 1), // width
            cursor.getInt(offset + 2), // height
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // groupPointsStr
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // groupTypeStr
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // imagePath
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, MagicPhotoEntity entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setWidth(cursor.getInt(offset + 1));
        entity.setHeight(cursor.getInt(offset + 2));
        entity.setGroupPointsStr(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setGroupTypeStr(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setImagePath(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(MagicPhotoEntity entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(MagicPhotoEntity entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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