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.RestaurantImage;
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 RestaurantImageDao extends AbstractDao<RestaurantImage, Long> {

    /*
    String id;
    String restaurant_id;
    String restaurant_branch_id;
    String image;
    */

    public static final String TABLENAME = "RestaurantImageTable";
    public static final String RESTAURANT_ID 	= "restaurant_id";
    public static final String RESTAURANT_BRANCH_ID 	= "restaurant_branch_id";
    public static final String IMAGE 	    = "image";

    /**
     * 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 Restaurant_id	    = new Property(++c, String.class, 	RESTAURANT_ID, 	false, RESTAURANT_ID);
        public final static Property Restaurant_branch_id 	= new Property(++c, String.class, 	RESTAURANT_BRANCH_ID, 	false, RESTAURANT_BRANCH_ID);
        public final static Property Image	    = new Property(++c, String.class, 	IMAGE, 	    false, IMAGE);
    };

    private DaoSession daoSession;

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

    public RestaurantImageDao(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 + RESTAURANT_ID + Dao.Q + Dao.TYPE_TEXT + Dao.COMMA +
                Dao.Q + RESTAURANT_BRANCH_ID + Dao.Q + Dao.TYPE_TEXT + Dao.COMMA +
                Dao.Q + IMAGE + Dao.Q + Dao.TYPE_TEXT
                + Dao.END_TABLE);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, RestaurantImage entity) {
    	 stmt.clearBindings();
    	 
         int c = 0;         
         Long id = entity.getId();
         ++c;
         if (id != null) {
         	 stmt.bindLong(c, id);
         }
        ++c; stmt.bindString(c, handleNull(entity.getRestaurant_id()));
        ++c; stmt.bindString(c, handleNull(entity.getRestaurant_branch_id()));
        ++c; stmt.bindString(c, handleNull(entity.getImage()));
    }

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

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

        RestaurantImage entity = new RestaurantImage(
			 cursor.isNull(offset + c) ? null : cursor.getLong(offset + c), // id
                cursor.getString(offset + ++c),
                cursor.getString(offset + ++c),
                cursor.getString(offset + ++c)
        );
        return entity;
    }
    
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, RestaurantImage entity, int offset) {
    	
    	int c = 0;
    	entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setRestaurant_id(cursor.getString(offset + ++c));
        entity.setRestaurant_branch_id(cursor.getString(offset + ++c));
        entity.setImage(cursor.getString(offset + ++c));

     }

    //  ===== BELOW THIS WILL NEVER CHANGE ======
    
    
    
    @Override
    protected void attachEntity(RestaurantImage 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(RestaurantImage entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(RestaurantImage entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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