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

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

    public static final String TABLENAME = "MS_ACCOUNT";

    /**
     * Properties of entity Account.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Uuid_account = new Property(0, String.class, "uuid_account", true, "UUID_ACCOUNT");
        public final static Property Account_name = new Property(1, String.class, "account_name", false, "ACCOUNT_NAME");
        public final static Property Account_address = new Property(2, String.class, "account_address", false, "ACCOUNT_ADDRESS");
        public final static Property Account_phone_1 = new Property(3, String.class, "account_phone_1", false, "ACCOUNT_PHONE_1");
        public final static Property Account_phone_2 = new Property(4, String.class, "account_phone_2", false, "ACCOUNT_PHONE_2");
        public final static Property Account_latitude = new Property(5, String.class, "account_latitude", false, "ACCOUNT_LATITUDE");
        public final static Property Account_longitude = new Property(6, String.class, "account_longitude", false, "ACCOUNT_LONGITUDE");
        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 AccountDao(DaoConfig config) {
        super(config);
    }
    
    public AccountDao(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_ACCOUNT\" (" + //
                "\"UUID_ACCOUNT\" TEXT PRIMARY KEY NOT NULL ," + // 0: uuid_account
                "\"ACCOUNT_NAME\" TEXT," + // 1: account_name
                "\"ACCOUNT_ADDRESS\" TEXT," + // 2: account_address
                "\"ACCOUNT_PHONE_1\" TEXT," + // 3: account_phone_1
                "\"ACCOUNT_PHONE_2\" TEXT," + // 4: account_phone_2
                "\"ACCOUNT_LATITUDE\" TEXT," + // 5: account_latitude
                "\"ACCOUNT_LONGITUDE\" TEXT," + // 6: account_longitude
                "\"USR_CRT\" TEXT," + // 7: usr_crt
                "\"DTM_CRT\" INTEGER);"); // 8: dtm_crt
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(DatabaseStatement stmt, Account entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getUuid_account());
 
        String account_name = entity.getAccount_name();
        if (account_name != null) {
            stmt.bindString(2, account_name);
        }
 
        String account_address = entity.getAccount_address();
        if (account_address != null) {
            stmt.bindString(3, account_address);
        }
 
        String account_phone_1 = entity.getAccount_phone_1();
        if (account_phone_1 != null) {
            stmt.bindString(4, account_phone_1);
        }
 
        String account_phone_2 = entity.getAccount_phone_2();
        if (account_phone_2 != null) {
            stmt.bindString(5, account_phone_2);
        }
 
        String account_latitude = entity.getAccount_latitude();
        if (account_latitude != null) {
            stmt.bindString(6, account_latitude);
        }
 
        String account_longitude = entity.getAccount_longitude();
        if (account_longitude != null) {
            stmt.bindString(7, account_longitude);
        }
 
        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());
        }
    }

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

    /** @inheritdoc */
    @Override
    public Account readEntity(Cursor cursor, int offset) {
        Account entity = new Account( //
            cursor.getString(offset + 0), // uuid_account
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // account_name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // account_address
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // account_phone_1
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // account_phone_2
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // account_latitude
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // account_longitude
            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
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Account entity, int offset) {
        entity.setUuid_account(cursor.getString(offset + 0));
        entity.setAccount_name(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setAccount_address(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setAccount_phone_1(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setAccount_phone_2(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setAccount_latitude(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setAccount_longitude(cursor.isNull(offset + 6) ? null : cursor.getString(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)));
     }
    
    /** @inheritdoc */
    @Override
    protected String updateKeyAfterInsert(Account entity, long rowId) {
        return entity.getUuid_account();
    }
    
    /** @inheritdoc */
    @Override
    public String getKey(Account entity) {
        if(entity != null) {
            return entity.getUuid_account();
        } else {
            return null;
        }
    }

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