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

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

    public static final String TABLENAME = "MS_CONTACT";

    /**
     * Properties of entity Contact.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Uuid_contact = new Property(0, String.class, "uuid_contact", true, "UUID_CONTACT");
        public final static Property Contact_name = new Property(1, String.class, "contact_name", false, "CONTACT_NAME");
        public final static Property Contact_dept = new Property(2, String.class, "contact_dept", false, "CONTACT_DEPT");
        public final static Property Contact_phone = new Property(3, String.class, "contact_phone", false, "CONTACT_PHONE");
        public final static Property Contact_email = new Property(4, String.class, "contact_email", false, "CONTACT_EMAIL");
        public final static Property Uuid_account = new Property(5, String.class, "uuid_account", false, "UUID_ACCOUNT");
        public final static Property Dtm_crt = new Property(6, java.util.Date.class, "dtm_crt", false, "DTM_CRT");
    };


    public ContactDao(DaoConfig config) {
        super(config);
    }
    
    public ContactDao(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_CONTACT\" (" + //
                "\"UUID_CONTACT\" TEXT PRIMARY KEY NOT NULL ," + // 0: uuid_contact
                "\"CONTACT_NAME\" TEXT," + // 1: contact_name
                "\"CONTACT_DEPT\" TEXT," + // 2: contact_dept
                "\"CONTACT_PHONE\" TEXT," + // 3: contact_phone
                "\"CONTACT_EMAIL\" TEXT," + // 4: contact_email
                "\"UUID_ACCOUNT\" TEXT," + // 5: uuid_account
                "\"DTM_CRT\" INTEGER);"); // 6: dtm_crt
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(DatabaseStatement stmt, Contact entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getUuid_contact());
 
        String contact_name = entity.getContact_name();
        if (contact_name != null) {
            stmt.bindString(2, contact_name);
        }
 
        String contact_dept = entity.getContact_dept();
        if (contact_dept != null) {
            stmt.bindString(3, contact_dept);
        }
 
        String contact_phone = entity.getContact_phone();
        if (contact_phone != null) {
            stmt.bindString(4, contact_phone);
        }
 
        String contact_email = entity.getContact_email();
        if (contact_email != null) {
            stmt.bindString(5, contact_email);
        }
 
        String uuid_account = entity.getUuid_account();
        if (uuid_account != null) {
            stmt.bindString(6, uuid_account);
        }
 
        java.util.Date dtm_crt = entity.getDtm_crt();
        if (dtm_crt != null) {
            stmt.bindLong(7, dtm_crt.getTime());
        }
    }

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

    /** @inheritdoc */
    @Override
    public Contact readEntity(Cursor cursor, int offset) {
        Contact entity = new Contact( //
            cursor.getString(offset + 0), // uuid_contact
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // contact_name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // contact_dept
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // contact_phone
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // contact_email
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // uuid_account
            cursor.isNull(offset + 6) ? null : new java.util.Date(cursor.getLong(offset + 6)) // dtm_crt
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Contact entity, int offset) {
        entity.setUuid_contact(cursor.getString(offset + 0));
        entity.setContact_name(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setContact_dept(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setContact_phone(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setContact_email(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setUuid_account(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setDtm_crt(cursor.isNull(offset + 6) ? null : new java.util.Date(cursor.getLong(offset + 6)));
     }
    
    /** @inheritdoc */
    @Override
    protected String updateKeyAfterInsert(Contact entity, long rowId) {
        return entity.getUuid_contact();
    }
    
    /** @inheritdoc */
    @Override
    public String getKey(Contact entity) {
        if(entity != null) {
            return entity.getUuid_contact();
        } else {
            return null;
        }
    }

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