package com.adins.mss.dao;

import android.database.Cursor;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;
import de.greenrobot.dao.database.Database;
import de.greenrobot.dao.database.DatabaseStatement;

import com.adins.mss.dao.Product;

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

    public static final String TABLENAME = "MS_PRODUCT";

    /**
     * Properties of entity Product.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Uuid_product = new Property(0, String.class, "uuid_product", true, "UUID_PRODUCT");
        public final static Property Product_code = new Property(1, String.class, "product_code", false, "PRODUCT_CODE");
        public final static Property Product_name = new Property(2, String.class, "product_name", false, "PRODUCT_NAME");
        public final static Property Product_desc = new Property(3, String.class, "product_desc", false, "PRODUCT_DESC");
        public final static Property Product_value = new Property(4, Integer.class, "product_value", false, "PRODUCT_VALUE");
        public final static Property Product_inctv_prctg = new Property(5, Integer.class, "product_inctv_prctg", false, "PRODUCT_INCTV_PRCTG");
        public final static Property Lob_image = new Property(6, byte[].class, "lob_image", false, "LOB_IMAGE");
        public final static Property Usr_crt = new Property(7, String.class, "usr_crt", false, "USR_CRT");
        public final static Property Dtm_crt = new Property(8, java.util.Date.class, "dtm_crt", false, "DTM_CRT");
        public final static Property Is_active = new Property(9, String.class, "is_active", false, "IS_ACTIVE");
        public final static Property Brand = new Property(10, String.class, "brand", false, "BRAND");
        public final static Property Type = new Property(11, String.class, "type", false, "TYPE");
        public final static Property Model = new Property(12, String.class, "model", false, "MODEL");
        public final static Property Product_file = new Property(13, String.class, "product_file", false, "PRODUCT_FILE");
    };


    public ProductDao(DaoConfig config) {
        super(config);
    }
    
    public ProductDao(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 + "\"MS_PRODUCT\" (" + //
                "\"UUID_PRODUCT\" TEXT PRIMARY KEY NOT NULL ," + // 0: uuid_product
                "\"PRODUCT_CODE\" TEXT," + // 1: product_code
                "\"PRODUCT_NAME\" TEXT," + // 2: product_name
                "\"PRODUCT_DESC\" TEXT," + // 3: product_desc
                "\"PRODUCT_VALUE\" INTEGER," + // 4: product_value
                "\"PRODUCT_INCTV_PRCTG\" INTEGER," + // 5: product_inctv_prctg
                "\"LOB_IMAGE\" BLOB," + // 6: lob_image
                "\"USR_CRT\" TEXT," + // 7: usr_crt
                "\"DTM_CRT\" INTEGER," + // 8: dtm_crt
                "\"IS_ACTIVE\" TEXT," + // 9: is_active
                "\"BRAND\" TEXT," + // 10: brand
                "\"TYPE\" TEXT," + // 11: type
                "\"MODEL\" TEXT," + // 12: model
                "\"PRODUCT_FILE\" TEXT);"); // 13: product_file
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(DatabaseStatement stmt, Product entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getUuid_product());
 
        String product_code = entity.getProduct_code();
        if (product_code != null) {
            stmt.bindString(2, product_code);
        }
 
        String product_name = entity.getProduct_name();
        if (product_name != null) {
            stmt.bindString(3, product_name);
        }
 
        String product_desc = entity.getProduct_desc();
        if (product_desc != null) {
            stmt.bindString(4, product_desc);
        }
 
        Integer product_value = entity.getProduct_value();
        if (product_value != null) {
            stmt.bindLong(5, product_value);
        }
 
        Integer product_inctv_prctg = entity.getProduct_inctv_prctg();
        if (product_inctv_prctg != null) {
            stmt.bindLong(6, product_inctv_prctg);
        }
 
        byte[] lob_image = entity.getLob_image();
        if (lob_image != null) {
            stmt.bindBlob(7, lob_image);
        }
 
        String usr_crt = entity.getUsr_crt();
        if (usr_crt != null) {
            stmt.bindString(8, usr_crt);
        }
 
        java.util.Date dtm_crt = entity.getDtm_crt();
        if (dtm_crt != null) {
            stmt.bindLong(9, dtm_crt.getTime());
        }
 
        String is_active = entity.getIs_active();
        if (is_active != null) {
            stmt.bindString(10, is_active);
        }
 
        String brand = entity.getBrand();
        if (brand != null) {
            stmt.bindString(11, brand);
        }
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(12, type);
        }
 
        String model = entity.getModel();
        if (model != null) {
            stmt.bindString(13, model);
        }
 
        String product_file = entity.getProduct_file();
        if (product_file != null) {
            stmt.bindString(14, product_file);
        }
    }

    /** @inheritdoc */
    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.getString(offset + 0);
    }    

    /** @inheritdoc */
    @Override
    public Product readEntity(Cursor cursor, int offset) {
        Product entity = new Product( //
            cursor.getString(offset + 0), // uuid_product
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // product_code
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // product_name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // product_desc
            cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4), // product_value
            cursor.isNull(offset + 5) ? null : cursor.getInt(offset + 5), // product_inctv_prctg
            cursor.isNull(offset + 6) ? null : cursor.getBlob(offset + 6), // lob_image
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // usr_crt
            cursor.isNull(offset + 8) ? null : new java.util.Date(cursor.getLong(offset + 8)), // dtm_crt
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // is_active
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // brand
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // type
            cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // model
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13) // product_file
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Product entity, int offset) {
        entity.setUuid_product(cursor.getString(offset + 0));
        entity.setProduct_code(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setProduct_name(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setProduct_desc(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setProduct_value(cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4));
        entity.setProduct_inctv_prctg(cursor.isNull(offset + 5) ? null : cursor.getInt(offset + 5));
        entity.setLob_image(cursor.isNull(offset + 6) ? null : cursor.getBlob(offset + 6));
        entity.setUsr_crt(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setDtm_crt(cursor.isNull(offset + 8) ? null : new java.util.Date(cursor.getLong(offset + 8)));
        entity.setIs_active(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setBrand(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setType(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setModel(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
        entity.setProduct_file(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
     }
    
    /** @inheritdoc */
    @Override
    protected String updateKeyAfterInsert(Product entity, long rowId) {
        return entity.getUuid_product();
    }
    
    /** @inheritdoc */
    @Override
    public String getKey(Product entity) {
        if(entity != null) {
            return entity.getUuid_product();
        } else {
            return null;
        }
    }

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