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.OfflineWork.domain.List_String_Converter;
import java.util.List;

import com.tofly.ghrq_route.module.OfflineWork.domain.OfflineWorkJobBean;

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

    public static final String TABLENAME = "DB_OFFLINE_WORK_JOB";

    /**
     * Properties of entity OfflineWorkJobBean.<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 Job_type = new Property(1, int.class, "job_type", false, "JOB_TYPE");
        public final static Property Ref_id = new Property(2, String.class, "ref_id", false, "REF_ID");
        public final static Property Ref_photo_ids = new Property(3, String.class, "ref_photo_ids", false, "REF_PHOTO_IDS");
        public final static Property Ref_audio_ids = new Property(4, String.class, "ref_audio_ids", false, "REF_AUDIO_IDS");
        public final static Property Ref_data_ids = new Property(5, String.class, "ref_data_ids", false, "REF_DATA_IDS");
        public final static Property Ref_data_id = new Property(6, String.class, "ref_data_id", false, "REF_DATA_ID");
        public final static Property Is_upload = new Property(7, int.class, "is_upload", false, "IS_UPLOAD");
        public final static Property Need_backapi = new Property(8, int.class, "need_backapi", false, "NEED_BACKAPI");
        public final static Property User_id = new Property(9, String.class, "user_id", false, "USER_ID");
    }

    private final List_String_Converter ref_photo_idsConverter = new List_String_Converter();
    private final List_String_Converter ref_audio_idsConverter = new List_String_Converter();
    private final List_String_Converter ref_data_idsConverter = new List_String_Converter();

    public OfflineWorkJobBeanDao(DaoConfig config) {
        super(config);
    }
    
    public OfflineWorkJobBeanDao(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_OFFLINE_WORK_JOB\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL UNIQUE ," + // 0: id
                "\"JOB_TYPE\" INTEGER NOT NULL ," + // 1: job_type
                "\"REF_ID\" TEXT," + // 2: ref_id
                "\"REF_PHOTO_IDS\" TEXT," + // 3: ref_photo_ids
                "\"REF_AUDIO_IDS\" TEXT," + // 4: ref_audio_ids
                "\"REF_DATA_IDS\" TEXT," + // 5: ref_data_ids
                "\"REF_DATA_ID\" TEXT," + // 6: ref_data_id
                "\"IS_UPLOAD\" INTEGER NOT NULL ," + // 7: is_upload
                "\"NEED_BACKAPI\" INTEGER NOT NULL ," + // 8: need_backapi
                "\"USER_ID\" TEXT);"); // 9: user_id
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, OfflineWorkJobBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
        stmt.bindLong(2, entity.getJob_type());
 
        String ref_id = entity.getRef_id();
        if (ref_id != null) {
            stmt.bindString(3, ref_id);
        }
 
        List ref_photo_ids = entity.getRef_photo_ids();
        if (ref_photo_ids != null) {
            stmt.bindString(4, ref_photo_idsConverter.convertToDatabaseValue(ref_photo_ids));
        }
 
        List ref_audio_ids = entity.getRef_audio_ids();
        if (ref_audio_ids != null) {
            stmt.bindString(5, ref_audio_idsConverter.convertToDatabaseValue(ref_audio_ids));
        }
 
        List ref_data_ids = entity.getRef_data_ids();
        if (ref_data_ids != null) {
            stmt.bindString(6, ref_data_idsConverter.convertToDatabaseValue(ref_data_ids));
        }
 
        String ref_data_id = entity.getRef_data_id();
        if (ref_data_id != null) {
            stmt.bindString(7, ref_data_id);
        }
        stmt.bindLong(8, entity.getIs_upload());
        stmt.bindLong(9, entity.getNeed_backapi());
 
        String user_id = entity.getUser_id();
        if (user_id != null) {
            stmt.bindString(10, user_id);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, OfflineWorkJobBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
        stmt.bindLong(2, entity.getJob_type());
 
        String ref_id = entity.getRef_id();
        if (ref_id != null) {
            stmt.bindString(3, ref_id);
        }
 
        List ref_photo_ids = entity.getRef_photo_ids();
        if (ref_photo_ids != null) {
            stmt.bindString(4, ref_photo_idsConverter.convertToDatabaseValue(ref_photo_ids));
        }
 
        List ref_audio_ids = entity.getRef_audio_ids();
        if (ref_audio_ids != null) {
            stmt.bindString(5, ref_audio_idsConverter.convertToDatabaseValue(ref_audio_ids));
        }
 
        List ref_data_ids = entity.getRef_data_ids();
        if (ref_data_ids != null) {
            stmt.bindString(6, ref_data_idsConverter.convertToDatabaseValue(ref_data_ids));
        }
 
        String ref_data_id = entity.getRef_data_id();
        if (ref_data_id != null) {
            stmt.bindString(7, ref_data_id);
        }
        stmt.bindLong(8, entity.getIs_upload());
        stmt.bindLong(9, entity.getNeed_backapi());
 
        String user_id = entity.getUser_id();
        if (user_id != null) {
            stmt.bindString(10, user_id);
        }
    }

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

    @Override
    public OfflineWorkJobBean readEntity(Cursor cursor, int offset) {
        OfflineWorkJobBean entity = new OfflineWorkJobBean( //
            cursor.getString(offset + 0), // id
            cursor.getInt(offset + 1), // job_type
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // ref_id
            cursor.isNull(offset + 3) ? null : ref_photo_idsConverter.convertToEntityProperty(cursor.getString(offset + 3)), // ref_photo_ids
            cursor.isNull(offset + 4) ? null : ref_audio_idsConverter.convertToEntityProperty(cursor.getString(offset + 4)), // ref_audio_ids
            cursor.isNull(offset + 5) ? null : ref_data_idsConverter.convertToEntityProperty(cursor.getString(offset + 5)), // ref_data_ids
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // ref_data_id
            cursor.getInt(offset + 7), // is_upload
            cursor.getInt(offset + 8), // need_backapi
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // user_id
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, OfflineWorkJobBean entity, int offset) {
        entity.setId(cursor.getString(offset + 0));
        entity.setJob_type(cursor.getInt(offset + 1));
        entity.setRef_id(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setRef_photo_ids(cursor.isNull(offset + 3) ? null : ref_photo_idsConverter.convertToEntityProperty(cursor.getString(offset + 3)));
        entity.setRef_audio_ids(cursor.isNull(offset + 4) ? null : ref_audio_idsConverter.convertToEntityProperty(cursor.getString(offset + 4)));
        entity.setRef_data_ids(cursor.isNull(offset + 5) ? null : ref_data_idsConverter.convertToEntityProperty(cursor.getString(offset + 5)));
        entity.setRef_data_id(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setIs_upload(cursor.getInt(offset + 7));
        entity.setNeed_backapi(cursor.getInt(offset + 8));
        entity.setUser_id(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
     }
    
    @Override
    protected final String updateKeyAfterInsert(OfflineWorkJobBean entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(OfflineWorkJobBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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