package com.tofly.data.sql.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.tofly.ghrq_route.module.troubleType.domain.TroubleRiskLevelBean;

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

    public static final String TABLENAME = "DB_TROUBLE_RISK_LEVEL";

    /**
     * Properties of entity TroubleRiskLevelBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, String.class, "id", true, "ID");
        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
        public final static Property Notes = new Property(2, String.class, "notes", false, "NOTES");
        public final static Property Category = new Property(3, String.class, "category", false, "CATEGORY");
        public final static Property Ischeck = new Property(4, boolean.class, "ischeck", false, "ISCHECK");
        public final static Property Issubmit = new Property(5, boolean.class, "issubmit", false, "ISSUBMIT");
    }


    public TroubleRiskLevelBeanDao(DaoConfig config) {
        super(config);
    }
    
    public TroubleRiskLevelBeanDao(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 + "\"DB_TROUBLE_RISK_LEVEL\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL UNIQUE ," + // 0: id
                "\"NAME\" TEXT," + // 1: name
                "\"NOTES\" TEXT," + // 2: notes
                "\"CATEGORY\" TEXT," + // 3: category
                "\"ISCHECK\" INTEGER NOT NULL ," + // 4: ischeck
                "\"ISSUBMIT\" INTEGER NOT NULL );"); // 5: issubmit
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, TroubleRiskLevelBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String notes = entity.getNotes();
        if (notes != null) {
            stmt.bindString(3, notes);
        }
 
        String category = entity.getCategory();
        if (category != null) {
            stmt.bindString(4, category);
        }
        stmt.bindLong(5, entity.getIscheck() ? 1L: 0L);
        stmt.bindLong(6, entity.getIssubmit() ? 1L: 0L);
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, TroubleRiskLevelBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String notes = entity.getNotes();
        if (notes != null) {
            stmt.bindString(3, notes);
        }
 
        String category = entity.getCategory();
        if (category != null) {
            stmt.bindString(4, category);
        }
        stmt.bindLong(5, entity.getIscheck() ? 1L: 0L);
        stmt.bindLong(6, entity.getIssubmit() ? 1L: 0L);
    }

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

    @Override
    public TroubleRiskLevelBean readEntity(Cursor cursor, int offset) {
        TroubleRiskLevelBean entity = new TroubleRiskLevelBean( //
            cursor.getString(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // notes
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // category
            cursor.getShort(offset + 4) != 0, // ischeck
            cursor.getShort(offset + 5) != 0 // issubmit
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, TroubleRiskLevelBean entity, int offset) {
        entity.setId(cursor.getString(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setNotes(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setCategory(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setIscheck(cursor.getShort(offset + 4) != 0);
        entity.setIssubmit(cursor.getShort(offset + 5) != 0);
     }
    
    @Override
    protected final String updateKeyAfterInsert(TroubleRiskLevelBean entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(TroubleRiskLevelBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(TroubleRiskLevelBean entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
