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.ReceiptHistory;

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

    public static final String TABLENAME = "TR_RECEIPTHISTORY";

    /**
     * Properties of entity ReceiptHistory.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Uuid_receipt_history = new Property(0, String.class, "uuid_receipt_history", true, "UUID_RECEIPT_HISTORY");
        public final static Property Uuid_task_h = new Property(1, String.class, "uuid_task_h", false, "UUID_TASK_H");
        public final static Property Agreement_no = new Property(2, String.class, "agreement_no", false, "AGREEMENT_NO");
        public final static Property Receipt_no = new Property(3, String.class, "receipt_no", false, "RECEIPT_NO");
        public final static Property Payment_date = new Property(4, String.class, "payment_date", false, "PAYMENT_DATE");
    };


    public ReceiptHistoryDao(DaoConfig config) {
        super(config);
    }
    
    public ReceiptHistoryDao(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 + "\"TR_RECEIPTHISTORY\" (" + //
                "\"UUID_RECEIPT_HISTORY\" TEXT PRIMARY KEY NOT NULL ," + // 0: uuid_receipt_history
                "\"UUID_TASK_H\" TEXT," + // 1: uuid_task_h
                "\"AGREEMENT_NO\" TEXT," + // 2: agreement_no
                "\"RECEIPT_NO\" TEXT," + // 3: receipt_no
                "\"PAYMENT_DATE\" TEXT);"); // 4: payment_date
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(DatabaseStatement stmt, ReceiptHistory entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getUuid_receipt_history());
 
        String uuid_task_h = entity.getUuid_task_h();
        if (uuid_task_h != null) {
            stmt.bindString(2, uuid_task_h);
        }
 
        String agreement_no = entity.getAgreement_no();
        if (agreement_no != null) {
            stmt.bindString(3, agreement_no);
        }
 
        String receipt_no = entity.getReceipt_no();
        if (receipt_no != null) {
            stmt.bindString(4, receipt_no);
        }
 
        String payment_date = entity.getPayment_date();
        if (payment_date != null) {
            stmt.bindString(5, payment_date);
        }
    }

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

    /** @inheritdoc */
    @Override
    public ReceiptHistory readEntity(Cursor cursor, int offset) {
        ReceiptHistory entity = new ReceiptHistory( //
            cursor.getString(offset + 0), // uuid_receipt_history
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // uuid_task_h
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // agreement_no
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // receipt_no
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // payment_date
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, ReceiptHistory entity, int offset) {
        entity.setUuid_receipt_history(cursor.getString(offset + 0));
        entity.setUuid_task_h(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setAgreement_no(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setReceipt_no(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setPayment_date(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
     }
    
    /** @inheritdoc */
    @Override
    protected String updateKeyAfterInsert(ReceiptHistory entity, long rowId) {
        return entity.getUuid_receipt_history();
    }
    
    /** @inheritdoc */
    @Override
    public String getKey(ReceiptHistory entity) {
        if(entity != null) {
            return entity.getUuid_receipt_history();
        } else {
            return null;
        }
    }

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