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 com.tofly.ghrq_route.module.planPointRepair.domain.AdjustRepairContent.List_RepairContent_Converter;
import java.util.List;

import com.tofly.ghrq_route.module.planPointRepair.domain.PlanPointRepair;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "DB_POINT_REPAIR".
*/
public class PlanPointRepairDao extends AbstractDao<PlanPointRepair, Long> {

    public static final String TABLENAME = "DB_POINT_REPAIR";

    /**
     * Properties of entity PlanPointRepair.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Temp_id = new Property(1, String.class, "temp_id", false, "TEMP_ID");
        public final static Property Point_id = new Property(2, String.class, "point_id", false, "POINT_ID");
        public final static Property Lng = new Property(3, double.class, "lng", false, "LNG");
        public final static Property Lat = new Property(4, double.class, "lat", false, "LAT");
        public final static Property Address = new Property(5, String.class, "address", false, "ADDRESS");
        public final static Property Code = new Property(6, String.class, "code", false, "CODE");
        public final static Property Create_time = new Property(7, String.class, "create_time", false, "CREATE_TIME");
        public final static Property Is_in_place = new Property(8, int.class, "is_in_place", false, "IS_IN_PLACE");
        public final static Property Notes = new Property(9, String.class, "notes", false, "NOTES");
        public final static Property Point_name = new Property(10, String.class, "point_name", false, "POINT_NAME");
        public final static Property Plan_point_id = new Property(11, String.class, "plan_point_id", false, "PLAN_POINT_ID");
        public final static Property Plan_id = new Property(12, String.class, "plan_id", false, "PLAN_ID");
        public final static Property DeviceUser = new Property(13, String.class, "deviceUser", false, "DEVICE_USER");
        public final static Property DeviceUserDeptId = new Property(14, String.class, "deviceUserDeptId", false, "DEVICE_USER_DEPT_ID");
        public final static Property CheckBeginDate = new Property(15, String.class, "checkBeginDate", false, "CHECK_BEGIN_DATE");
        public final static Property CheckEndDate = new Property(16, String.class, "checkEndDate", false, "CHECK_END_DATE");
        public final static Property CheckRegion = new Property(17, String.class, "checkRegion", false, "CHECK_REGION");
        public final static Property Content = new Property(18, String.class, "content", false, "CONTENT");
        public final static Property Contents = new Property(19, String.class, "contents", false, "CONTENTS");
        public final static Property State = new Property(20, int.class, "state", false, "STATE");
        public final static Property IsUpdating = new Property(21, boolean.class, "isUpdating", false, "IS_UPDATING");
    }

    private final List_String_Converter contentConverter = new List_String_Converter();
    private final List_RepairContent_Converter contentsConverter = new List_RepairContent_Converter();

    public PlanPointRepairDao(DaoConfig config) {
        super(config);
    }
    
    public PlanPointRepairDao(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_POINT_REPAIR\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"TEMP_ID\" TEXT," + // 1: temp_id
                "\"POINT_ID\" TEXT," + // 2: point_id
                "\"LNG\" REAL NOT NULL ," + // 3: lng
                "\"LAT\" REAL NOT NULL ," + // 4: lat
                "\"ADDRESS\" TEXT," + // 5: address
                "\"CODE\" TEXT," + // 6: code
                "\"CREATE_TIME\" TEXT," + // 7: create_time
                "\"IS_IN_PLACE\" INTEGER NOT NULL ," + // 8: is_in_place
                "\"NOTES\" TEXT," + // 9: notes
                "\"POINT_NAME\" TEXT," + // 10: point_name
                "\"PLAN_POINT_ID\" TEXT," + // 11: plan_point_id
                "\"PLAN_ID\" TEXT," + // 12: plan_id
                "\"DEVICE_USER\" TEXT," + // 13: deviceUser
                "\"DEVICE_USER_DEPT_ID\" TEXT," + // 14: deviceUserDeptId
                "\"CHECK_BEGIN_DATE\" TEXT," + // 15: checkBeginDate
                "\"CHECK_END_DATE\" TEXT," + // 16: checkEndDate
                "\"CHECK_REGION\" TEXT," + // 17: checkRegion
                "\"CONTENT\" TEXT," + // 18: content
                "\"CONTENTS\" TEXT," + // 19: contents
                "\"STATE\" INTEGER NOT NULL ," + // 20: state
                "\"IS_UPDATING\" INTEGER NOT NULL );"); // 21: isUpdating
        // Add Indexes
        db.execSQL("CREATE UNIQUE INDEX " + constraint + "IDX_DB_POINT_REPAIR_POINT_ID_DESC_PLAN_ID_DESC ON \"DB_POINT_REPAIR\"" +
                " (\"POINT_ID\" DESC,\"PLAN_ID\" DESC);");
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, PlanPointRepair entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String temp_id = entity.getTemp_id();
        if (temp_id != null) {
            stmt.bindString(2, temp_id);
        }
 
        String point_id = entity.getPoint_id();
        if (point_id != null) {
            stmt.bindString(3, point_id);
        }
        stmt.bindDouble(4, entity.getLng());
        stmt.bindDouble(5, entity.getLat());
 
        String address = entity.getAddress();
        if (address != null) {
            stmt.bindString(6, address);
        }
 
        String code = entity.getCode();
        if (code != null) {
            stmt.bindString(7, code);
        }
 
        String create_time = entity.getCreate_time();
        if (create_time != null) {
            stmt.bindString(8, create_time);
        }
        stmt.bindLong(9, entity.getIs_in_place());
 
        String notes = entity.getNotes();
        if (notes != null) {
            stmt.bindString(10, notes);
        }
 
        String point_name = entity.getPoint_name();
        if (point_name != null) {
            stmt.bindString(11, point_name);
        }
 
        String plan_point_id = entity.getPlan_point_id();
        if (plan_point_id != null) {
            stmt.bindString(12, plan_point_id);
        }
 
        String plan_id = entity.getPlan_id();
        if (plan_id != null) {
            stmt.bindString(13, plan_id);
        }
 
        String deviceUser = entity.getDeviceUser();
        if (deviceUser != null) {
            stmt.bindString(14, deviceUser);
        }
 
        String deviceUserDeptId = entity.getDeviceUserDeptId();
        if (deviceUserDeptId != null) {
            stmt.bindString(15, deviceUserDeptId);
        }
 
        String checkBeginDate = entity.getCheckBeginDate();
        if (checkBeginDate != null) {
            stmt.bindString(16, checkBeginDate);
        }
 
        String checkEndDate = entity.getCheckEndDate();
        if (checkEndDate != null) {
            stmt.bindString(17, checkEndDate);
        }
 
        String checkRegion = entity.getCheckRegion();
        if (checkRegion != null) {
            stmt.bindString(18, checkRegion);
        }
 
        List content = entity.getContent();
        if (content != null) {
            stmt.bindString(19, contentConverter.convertToDatabaseValue(content));
        }
 
        List contents = entity.getContents();
        if (contents != null) {
            stmt.bindString(20, contentsConverter.convertToDatabaseValue(contents));
        }
        stmt.bindLong(21, entity.getState());
        stmt.bindLong(22, entity.getIsUpdating() ? 1L: 0L);
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, PlanPointRepair entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String temp_id = entity.getTemp_id();
        if (temp_id != null) {
            stmt.bindString(2, temp_id);
        }
 
        String point_id = entity.getPoint_id();
        if (point_id != null) {
            stmt.bindString(3, point_id);
        }
        stmt.bindDouble(4, entity.getLng());
        stmt.bindDouble(5, entity.getLat());
 
        String address = entity.getAddress();
        if (address != null) {
            stmt.bindString(6, address);
        }
 
        String code = entity.getCode();
        if (code != null) {
            stmt.bindString(7, code);
        }
 
        String create_time = entity.getCreate_time();
        if (create_time != null) {
            stmt.bindString(8, create_time);
        }
        stmt.bindLong(9, entity.getIs_in_place());
 
        String notes = entity.getNotes();
        if (notes != null) {
            stmt.bindString(10, notes);
        }
 
        String point_name = entity.getPoint_name();
        if (point_name != null) {
            stmt.bindString(11, point_name);
        }
 
        String plan_point_id = entity.getPlan_point_id();
        if (plan_point_id != null) {
            stmt.bindString(12, plan_point_id);
        }
 
        String plan_id = entity.getPlan_id();
        if (plan_id != null) {
            stmt.bindString(13, plan_id);
        }
 
        String deviceUser = entity.getDeviceUser();
        if (deviceUser != null) {
            stmt.bindString(14, deviceUser);
        }
 
        String deviceUserDeptId = entity.getDeviceUserDeptId();
        if (deviceUserDeptId != null) {
            stmt.bindString(15, deviceUserDeptId);
        }
 
        String checkBeginDate = entity.getCheckBeginDate();
        if (checkBeginDate != null) {
            stmt.bindString(16, checkBeginDate);
        }
 
        String checkEndDate = entity.getCheckEndDate();
        if (checkEndDate != null) {
            stmt.bindString(17, checkEndDate);
        }
 
        String checkRegion = entity.getCheckRegion();
        if (checkRegion != null) {
            stmt.bindString(18, checkRegion);
        }
 
        List content = entity.getContent();
        if (content != null) {
            stmt.bindString(19, contentConverter.convertToDatabaseValue(content));
        }
 
        List contents = entity.getContents();
        if (contents != null) {
            stmt.bindString(20, contentsConverter.convertToDatabaseValue(contents));
        }
        stmt.bindLong(21, entity.getState());
        stmt.bindLong(22, entity.getIsUpdating() ? 1L: 0L);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public PlanPointRepair readEntity(Cursor cursor, int offset) {
        PlanPointRepair entity = new PlanPointRepair( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // temp_id
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // point_id
            cursor.getDouble(offset + 3), // lng
            cursor.getDouble(offset + 4), // lat
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // address
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // code
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // create_time
            cursor.getInt(offset + 8), // is_in_place
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // notes
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // point_name
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // plan_point_id
            cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // plan_id
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // deviceUser
            cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // deviceUserDeptId
            cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // checkBeginDate
            cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // checkEndDate
            cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // checkRegion
            cursor.isNull(offset + 18) ? null : contentConverter.convertToEntityProperty(cursor.getString(offset + 18)), // content
            cursor.isNull(offset + 19) ? null : contentsConverter.convertToEntityProperty(cursor.getString(offset + 19)), // contents
            cursor.getInt(offset + 20), // state
            cursor.getShort(offset + 21) != 0 // isUpdating
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, PlanPointRepair entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setTemp_id(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setPoint_id(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setLng(cursor.getDouble(offset + 3));
        entity.setLat(cursor.getDouble(offset + 4));
        entity.setAddress(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setCode(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setCreate_time(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setIs_in_place(cursor.getInt(offset + 8));
        entity.setNotes(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setPoint_name(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setPlan_point_id(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setPlan_id(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
        entity.setDeviceUser(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
        entity.setDeviceUserDeptId(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
        entity.setCheckBeginDate(cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15));
        entity.setCheckEndDate(cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16));
        entity.setCheckRegion(cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17));
        entity.setContent(cursor.isNull(offset + 18) ? null : contentConverter.convertToEntityProperty(cursor.getString(offset + 18)));
        entity.setContents(cursor.isNull(offset + 19) ? null : contentsConverter.convertToEntityProperty(cursor.getString(offset + 19)));
        entity.setState(cursor.getInt(offset + 20));
        entity.setIsUpdating(cursor.getShort(offset + 21) != 0);
     }
    
    @Override
    protected final Long updateKeyAfterInsert(PlanPointRepair entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(PlanPointRepair entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(PlanPointRepair entity) {
        return entity.getId() != null;
    }

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