package hf.lskj.com.carstockcount.db;

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;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "CAR_INFO".
*/
public class CarInfoDao extends AbstractDao<CarInfo, String> {

    public static final String TABLENAME = "CAR_INFO";

    /**
     * Properties of entity CarInfo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Vin = new Property(0, String.class, "vin", true, "VIN");
        public final static Property Rfid = new Property(1, String.class, "rfid", false, "RFID");
        public final static Property StoreId = new Property(2, String.class, "storeId", false, "STORE_ID");
        public final static Property Color = new Property(3, String.class, "color", false, "COLOR");
        public final static Property Type = new Property(4, String.class, "type", false, "TYPE");
        public final static Property Status = new Property(5, String.class, "status", false, "STATUS");
        public final static Property StockCountTime = new Property(6, String.class, "stockCountTime", false, "STOCK_COUNT_TIME");
        public final static Property StockCountType = new Property(7, String.class, "stockCountType", false, "STOCK_COUNT_TYPE");
    }

    private DaoSession daoSession;


    public CarInfoDao(DaoConfig config) {
        super(config);
    }
    
    public CarInfoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = 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 + "\"CAR_INFO\" (" + //
                "\"VIN\" TEXT PRIMARY KEY NOT NULL ," + // 0: vin
                "\"RFID\" TEXT," + // 1: rfid
                "\"STORE_ID\" TEXT," + // 2: storeId
                "\"COLOR\" TEXT," + // 3: color
                "\"TYPE\" TEXT," + // 4: type
                "\"STATUS\" TEXT," + // 5: status
                "\"STOCK_COUNT_TIME\" TEXT," + // 6: stockCountTime
                "\"STOCK_COUNT_TYPE\" TEXT);"); // 7: stockCountType
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, CarInfo entity) {
        stmt.clearBindings();
 
        String vin = entity.getVin();
        if (vin != null) {
            stmt.bindString(1, vin);
        }
 
        String rfid = entity.getRfid();
        if (rfid != null) {
            stmt.bindString(2, rfid);
        }
 
        String storeId = entity.getStoreId();
        if (storeId != null) {
            stmt.bindString(3, storeId);
        }
 
        String color = entity.getColor();
        if (color != null) {
            stmt.bindString(4, color);
        }
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(5, type);
        }
 
        String status = entity.getStatus();
        if (status != null) {
            stmt.bindString(6, status);
        }
 
        String stockCountTime = entity.getStockCountTime();
        if (stockCountTime != null) {
            stmt.bindString(7, stockCountTime);
        }
 
        String stockCountType = entity.getStockCountType();
        if (stockCountType != null) {
            stmt.bindString(8, stockCountType);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, CarInfo entity) {
        stmt.clearBindings();
 
        String vin = entity.getVin();
        if (vin != null) {
            stmt.bindString(1, vin);
        }
 
        String rfid = entity.getRfid();
        if (rfid != null) {
            stmt.bindString(2, rfid);
        }
 
        String storeId = entity.getStoreId();
        if (storeId != null) {
            stmt.bindString(3, storeId);
        }
 
        String color = entity.getColor();
        if (color != null) {
            stmt.bindString(4, color);
        }
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(5, type);
        }
 
        String status = entity.getStatus();
        if (status != null) {
            stmt.bindString(6, status);
        }
 
        String stockCountTime = entity.getStockCountTime();
        if (stockCountTime != null) {
            stmt.bindString(7, stockCountTime);
        }
 
        String stockCountType = entity.getStockCountType();
        if (stockCountType != null) {
            stmt.bindString(8, stockCountType);
        }
    }

    @Override
    protected final void attachEntity(CarInfo entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

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

    @Override
    public CarInfo readEntity(Cursor cursor, int offset) {
        CarInfo entity = new CarInfo( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // vin
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // rfid
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // storeId
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // color
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // type
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // status
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // stockCountTime
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // stockCountType
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, CarInfo entity, int offset) {
        entity.setVin(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setRfid(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setStoreId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setColor(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setType(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setStatus(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setStockCountTime(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setStockCountType(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
     }
    
    @Override
    protected final String updateKeyAfterInsert(CarInfo entity, long rowId) {
        return entity.getVin();
    }
    
    @Override
    public String getKey(CarInfo entity) {
        if(entity != null) {
            return entity.getVin();
        } else {
            return null;
        }
    }

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

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