package com.androcid.zomato.dao.classes;


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

import com.androcid.zomato.dao.Dao;
import com.androcid.zomato.dao.DaoSession;
import com.androcid.zomato.model.PhotoItem;
import com.androcid.zomato.util.MyLg;

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

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

/**
 * DAO for table "+TABLENAME+".
*/
public class PhotoItemDao extends AbstractDao<PhotoItem, Long> {

    public static final String TABLENAME = "PhotoItemTable";
    public static final String PHOTO_ID 	= "photo_id";
    public static final String NAME 	= "name";
    public static final String PATH 	= "path";
    public static final String TAG 	    = "tag";
    public static final String STATUS 	= "status";

    /**
     * Properties of entity "+TABLENAME+".<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
    	static int c = -1;
        public final static Property _Id 		= new Property(++c, Long.class, 	Dao.ID, 		true,  Dao.COLUMN_ID);
        public final static Property Photo_id	= new Property(++c, String.class, 	PHOTO_ID, 	false, PHOTO_ID);
        public final static Property Name 	    = new Property(++c, String.class, 	NAME, 	false, NAME);
        public final static Property Path	    = new Property(++c, String.class, 	PATH, 	    false, PATH);
        public final static Property Tag	    = new Property(++c, String.class, 	TAG, 	    false, TAG);
        public final static Property Status	    = new Property(++c, Long.class, 	STATUS, 	    false, STATUS);
    };

    private DaoSession daoSession;

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

    public PhotoItemDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {

        MyLg.e(TABLENAME, "CREATE TABLE");

        String constraint = ifNotExists ? Dao.IF_NOT_EXIST : " ";
        db.execSQL(Dao.CREATE_TABLE + constraint + Dao.Q + TABLENAME + Dao.Q + Dao.START_TABLE +

                Dao.Q + Dao.COLUMN_ID + Dao.Q + Dao.TYPE_INTEGER_PRIMARY + Dao.COMMA +
                Dao.Q + PHOTO_ID + Dao.Q + Dao.TYPE_TEXT + Dao.COMMA +
                Dao.Q + NAME + Dao.Q + Dao.TYPE_TEXT + Dao.COMMA +
                Dao.Q + PATH + Dao.Q + Dao.TYPE_TEXT + Dao.COMMA +
                Dao.Q + TAG + Dao.Q + Dao.TYPE_TEXT + Dao.COMMA +
                Dao.Q + STATUS + Dao.Q + Dao.TYPE_INTEGER
                + Dao.END_TABLE);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, PhotoItem entity) {
    	 stmt.clearBindings();
    	 
         int c = 0;         
         Long id = entity.getId();
         ++c;
         if (id != null) {
         	 stmt.bindLong(c, id);
         }
        ++c; stmt.bindString(c, handleNull(entity.get_id()));
        ++c; stmt.bindString(c, handleNull(entity.getName()));
        ++c; stmt.bindString(c, handleNull(entity.getPath()));
        ++c; stmt.bindString(c, handleNull(entity.getTag()));
        ++c; stmt.bindLong(c, entity.isStatus()?1:0);
    }

    private String handleNull(String value) {
        if(value!=null)
            return value;
        return "";
    }

    /** @inheritdoc */
    @Override
    public PhotoItem readEntity(Cursor cursor, int offset) {
    	
    	int c = 0;

        PhotoItem entity = new PhotoItem(
			 cursor.isNull(offset + c) ? null : cursor.getLong(offset + c), // id
                cursor.getString(offset + ++c),
                cursor.getString(offset + ++c),
                cursor.getString(offset + ++c),
                cursor.getString(offset + ++c),
                cursor.getInt(offset + ++c) == 1
        );
        return entity;
    }
    
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, PhotoItem entity, int offset) {
    	
    	int c = 0;
    	entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.set_id(cursor.getString(offset + ++c));
        entity.setName(cursor.getString(offset + ++c));
        entity.setPath(cursor.getString(offset + ++c));
        entity.setTag(cursor.getString(offset + ++c));
        entity.setStatus(cursor.getInt(offset + ++c) == 1);

     }

    //  ===== BELOW THIS WILL NEVER CHANGE ======
    
    
    
    @Override
    protected void attachEntity(PhotoItem entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }


    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'"+TABLENAME+"'";
        db.execSQL(sql);
    }
    
    /** @inheritdoc */
    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    
         
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(PhotoItem entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(PhotoItem entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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