package com.gingersoft.gsa.cloud.database.greendao;

import java.util.List;
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 org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.gingersoft.gsa.cloud.database.bean.FoodCombo;

import com.gingersoft.gsa.cloud.database.bean.ComboItem;

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

    public static final String TABLENAME = "COMBO_ITEM";

    /**
     * Properties of entity ComboItem.<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 ComId = new Property(1, Long.class, "comId", false, "COM_ID");
        public final static Property Fid = new Property(2, Long.class, "fid", false, "FID");
        public final static Property Qty = new Property(3, Long.class, "qty", false, "QTY");
        public final static Property DiffAmt = new Property(4, Double.class, "diffAmt", false, "DIFF_AMT");
        public final static Property SeqNo = new Property(5, Long.class, "seqNo", false, "SEQ_NO");
        public final static Property Visible = new Property(6, Long.class, "visible", false, "VISIBLE");
        public final static Property CreateTime = new Property(7, java.util.Date.class, "createTime", false, "CREATE_TIME");
        public final static Property CreateBy = new Property(8, String.class, "createBy", false, "CREATE_BY");
        public final static Property UpdateTime = new Property(9, java.util.Date.class, "updateTime", false, "UPDATE_TIME");
        public final static Property Conditions = new Property(10, Long.class, "conditions", false, "CONDITIONS");
        public final static Property IsRT = new Property(11, Long.class, "isRT", false, "IS_RT");
        public final static Property Deletes = new Property(12, Byte.class, "deletes", false, "DELETES");
        public final static Property PosId = new Property(13, Long.class, "posId", false, "POS_ID");
        public final static Property Restaurant_id = new Property(14, Long.class, "restaurant_id", false, "RESTAURANT_ID");
        public final static Property IsMainAccount = new Property(15, Byte.class, "isMainAccount", false, "IS_MAIN_ACCOUNT");
    }

    private Query<ComboItem> food_ComboItemsQuery;

    public ComboItemDao(DaoConfig config) {
        super(config);
    }
    
    public ComboItemDao(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 + "\"COMBO_ITEM\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"COM_ID\" INTEGER," + // 1: comId
                "\"FID\" INTEGER," + // 2: fid
                "\"QTY\" INTEGER," + // 3: qty
                "\"DIFF_AMT\" REAL," + // 4: diffAmt
                "\"SEQ_NO\" INTEGER," + // 5: seqNo
                "\"VISIBLE\" INTEGER," + // 6: visible
                "\"CREATE_TIME\" INTEGER," + // 7: createTime
                "\"CREATE_BY\" TEXT," + // 8: createBy
                "\"UPDATE_TIME\" INTEGER," + // 9: updateTime
                "\"CONDITIONS\" INTEGER," + // 10: conditions
                "\"IS_RT\" INTEGER," + // 11: isRT
                "\"DELETES\" INTEGER," + // 12: deletes
                "\"POS_ID\" INTEGER," + // 13: posId
                "\"RESTAURANT_ID\" INTEGER," + // 14: restaurant_id
                "\"IS_MAIN_ACCOUNT\" INTEGER);"); // 15: isMainAccount
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, ComboItem entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long comId = entity.getComId();
        if (comId != null) {
            stmt.bindLong(2, comId);
        }
 
        Long fid = entity.getFid();
        if (fid != null) {
            stmt.bindLong(3, fid);
        }
 
        Long qty = entity.getQty();
        if (qty != null) {
            stmt.bindLong(4, qty);
        }
 
        Double diffAmt = entity.getDiffAmt();
        if (diffAmt != null) {
            stmt.bindDouble(5, diffAmt);
        }
 
        Long seqNo = entity.getSeqNo();
        if (seqNo != null) {
            stmt.bindLong(6, seqNo);
        }
 
        Long visible = entity.getVisible();
        if (visible != null) {
            stmt.bindLong(7, visible);
        }
 
        java.util.Date createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(8, createTime.getTime());
        }
 
        String createBy = entity.getCreateBy();
        if (createBy != null) {
            stmt.bindString(9, createBy);
        }
 
        java.util.Date updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindLong(10, updateTime.getTime());
        }
 
        Long conditions = entity.getConditions();
        if (conditions != null) {
            stmt.bindLong(11, conditions);
        }
 
        Long isRT = entity.getIsRT();
        if (isRT != null) {
            stmt.bindLong(12, isRT);
        }
 
        Byte deletes = entity.getDeletes();
        if (deletes != null) {
            stmt.bindLong(13, deletes);
        }
 
        Long posId = entity.getPosId();
        if (posId != null) {
            stmt.bindLong(14, posId);
        }
 
        Long restaurant_id = entity.getRestaurant_id();
        if (restaurant_id != null) {
            stmt.bindLong(15, restaurant_id);
        }
 
        Byte isMainAccount = entity.getIsMainAccount();
        if (isMainAccount != null) {
            stmt.bindLong(16, isMainAccount);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, ComboItem entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long comId = entity.getComId();
        if (comId != null) {
            stmt.bindLong(2, comId);
        }
 
        Long fid = entity.getFid();
        if (fid != null) {
            stmt.bindLong(3, fid);
        }
 
        Long qty = entity.getQty();
        if (qty != null) {
            stmt.bindLong(4, qty);
        }
 
        Double diffAmt = entity.getDiffAmt();
        if (diffAmt != null) {
            stmt.bindDouble(5, diffAmt);
        }
 
        Long seqNo = entity.getSeqNo();
        if (seqNo != null) {
            stmt.bindLong(6, seqNo);
        }
 
        Long visible = entity.getVisible();
        if (visible != null) {
            stmt.bindLong(7, visible);
        }
 
        java.util.Date createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(8, createTime.getTime());
        }
 
        String createBy = entity.getCreateBy();
        if (createBy != null) {
            stmt.bindString(9, createBy);
        }
 
        java.util.Date updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindLong(10, updateTime.getTime());
        }
 
        Long conditions = entity.getConditions();
        if (conditions != null) {
            stmt.bindLong(11, conditions);
        }
 
        Long isRT = entity.getIsRT();
        if (isRT != null) {
            stmt.bindLong(12, isRT);
        }
 
        Byte deletes = entity.getDeletes();
        if (deletes != null) {
            stmt.bindLong(13, deletes);
        }
 
        Long posId = entity.getPosId();
        if (posId != null) {
            stmt.bindLong(14, posId);
        }
 
        Long restaurant_id = entity.getRestaurant_id();
        if (restaurant_id != null) {
            stmt.bindLong(15, restaurant_id);
        }
 
        Byte isMainAccount = entity.getIsMainAccount();
        if (isMainAccount != null) {
            stmt.bindLong(16, isMainAccount);
        }
    }

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

    @Override
    public ComboItem readEntity(Cursor cursor, int offset) {
        ComboItem entity = new ComboItem( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // comId
            cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // fid
            cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3), // qty
            cursor.isNull(offset + 4) ? null : cursor.getDouble(offset + 4), // diffAmt
            cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5), // seqNo
            cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6), // visible
            cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)), // createTime
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // createBy
            cursor.isNull(offset + 9) ? null : new java.util.Date(cursor.getLong(offset + 9)), // updateTime
            cursor.isNull(offset + 10) ? null : cursor.getLong(offset + 10), // conditions
            cursor.isNull(offset + 11) ? null : cursor.getLong(offset + 11), // isRT
            cursor.isNull(offset + 12) ? null : (byte) cursor.getShort(offset + 12), // deletes
            cursor.isNull(offset + 13) ? null : cursor.getLong(offset + 13), // posId
            cursor.isNull(offset + 14) ? null : cursor.getLong(offset + 14), // restaurant_id
            cursor.isNull(offset + 15) ? null : (byte) cursor.getShort(offset + 15) // isMainAccount
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, ComboItem entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setComId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setFid(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2));
        entity.setQty(cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3));
        entity.setDiffAmt(cursor.isNull(offset + 4) ? null : cursor.getDouble(offset + 4));
        entity.setSeqNo(cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5));
        entity.setVisible(cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6));
        entity.setCreateTime(cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)));
        entity.setCreateBy(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setUpdateTime(cursor.isNull(offset + 9) ? null : new java.util.Date(cursor.getLong(offset + 9)));
        entity.setConditions(cursor.isNull(offset + 10) ? null : cursor.getLong(offset + 10));
        entity.setIsRT(cursor.isNull(offset + 11) ? null : cursor.getLong(offset + 11));
        entity.setDeletes(cursor.isNull(offset + 12) ? null : (byte) cursor.getShort(offset + 12));
        entity.setPosId(cursor.isNull(offset + 13) ? null : cursor.getLong(offset + 13));
        entity.setRestaurant_id(cursor.isNull(offset + 14) ? null : cursor.getLong(offset + 14));
        entity.setIsMainAccount(cursor.isNull(offset + 15) ? null : (byte) cursor.getShort(offset + 15));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(ComboItem entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(ComboItem entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "comboItems" to-many relationship of Food. */
    public List<ComboItem> _queryFood_ComboItems(Long fid) {
        synchronized (this) {
            if (food_ComboItemsQuery == null) {
                QueryBuilder<ComboItem> queryBuilder = queryBuilder();
                queryBuilder.join(FoodCombo.class, FoodComboDao.Properties.ComId)
                    .where(FoodComboDao.Properties.Fid.eq(fid));
                food_ComboItemsQuery = queryBuilder.build();
            }
        }
        Query<ComboItem> query = food_ComboItemsQuery.forCurrentThread();
        query.setParameter(0, fid);
        return query.list();
    }

}
