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

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

    public static final String TABLENAME = "TR_BROADCAST";

    /**
     * Properties of entity Broadcast.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Uuid_broadcast = new Property(0, String.class, "uuid_broadcast", true, "UUID_BROADCAST");
        public final static Property Title = new Property(1, String.class, "title", false, "TITLE");
        public final static Property Message = new Property(2, String.class, "message", false, "MESSAGE");
        public final static Property Is_shown = new Property(3, Boolean.class, "is_shown", false, "IS_SHOWN");
        public final static Property Dtm_crt = new Property(4, java.util.Date.class, "dtm_crt", false, "DTM_CRT");
    };


    public BroadcastDao(DaoConfig config) {
        super(config);
    }
    
    public BroadcastDao(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_BROADCAST\" (" + //
                "\"UUID_BROADCAST\" TEXT PRIMARY KEY NOT NULL ," + // 0: uuid_broadcast
                "\"TITLE\" TEXT," + // 1: title
                "\"MESSAGE\" TEXT," + // 2: message
                "\"IS_SHOWN\" INTEGER," + // 3: is_shown
                "\"DTM_CRT\" INTEGER);"); // 4: dtm_crt
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(DatabaseStatement stmt, Broadcast entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getUuid_broadcast());
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }
 
        String message = entity.getMessage();
        if (message != null) {
            stmt.bindString(3, message);
        }
 
        Boolean is_shown = entity.getIs_shown();
        if (is_shown != null) {
            stmt.bindLong(4, is_shown ? 1L: 0L);
        }
 
        java.util.Date dtm_crt = entity.getDtm_crt();
        if (dtm_crt != null) {
            stmt.bindLong(5, dtm_crt.getTime());
        }
    }

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

    /** @inheritdoc */
    @Override
    public Broadcast readEntity(Cursor cursor, int offset) {
        Broadcast entity = new Broadcast( //
            cursor.getString(offset + 0), // uuid_broadcast
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // title
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // message
            cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3) != 0, // is_shown
            cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)) // dtm_crt
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Broadcast entity, int offset) {
        entity.setUuid_broadcast(cursor.getString(offset + 0));
        entity.setTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setMessage(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setIs_shown(cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3) != 0);
        entity.setDtm_crt(cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)));
     }
    
    /** @inheritdoc */
    @Override
    protected String updateKeyAfterInsert(Broadcast entity, long rowId) {
        return entity.getUuid_broadcast();
    }
    
    /** @inheritdoc */
    @Override
    public String getKey(Broadcast entity) {
        if(entity != null) {
            return entity.getUuid_broadcast();
        } else {
            return null;
        }
    }

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