package com.tofly.ghrq_route.module.troubleType;

import com.tofly.data.sql.dao.DaoSession;
import com.tofly.data.sql.dao.PipeTypeBeanDao;
import com.tofly.data.sql.dao.SysDeviceTypeBeanDao;
import com.tofly.data.sql.dao.TroubleRiskLevelBeanDao;
import com.tofly.data.sql.dao.TroubleTypeBeanDao;
import com.tofly.ghrq_route.module.sqlite.DBDaoHelper;
import com.tofly.ghrq_route.module.troubleType.domain.PipeTypeBean;
import com.tofly.ghrq_route.module.troubleType.domain.SysDeviceTypeBean;
import com.tofly.ghrq_route.module.troubleType.domain.TroubleRiskLevelBean;
import com.tofly.ghrq_route.module.troubleType.domain.TroubleTypeBean;

import java.util.List;

public class TroubleTypeDaoHelper {

    private static TroubleTypeDaoHelper ourInstance = new TroubleTypeDaoHelper();

    public static TroubleTypeDaoHelper getInstance() {
        return ourInstance;
    }

    private DBDaoHelper dbDaoHelper;
    private DaoSession daoSession;

    private TroubleTypeDaoHelper() {
        dbDaoHelper = DBDaoHelper.getInstance();
        daoSession = dbDaoHelper.getDaoSession();
    }

    /**
     * SysDeviceTypeBeanDao  隐患上传模块 UiDangerReport
     */
    /*保存服务器的隐患设备类型数据*/
    public void saveSysDeviceTypes(List<SysDeviceTypeBean> sysDeviceTypeBeans) {
        deleteAllSysDeviceTypes();
        SysDeviceTypeBeanDao sysDeviceTypeBeanDao = daoSession.getSysDeviceTypeBeanDao();
        sysDeviceTypeBeanDao.insertOrReplaceInTx(sysDeviceTypeBeans);
    }

    /*读取本地保存的隐患设备类型列表*/
    public List<SysDeviceTypeBean> getSysDeviceTypeList() {
        SysDeviceTypeBeanDao sysDeviceTypeBeanDao = daoSession.getSysDeviceTypeBeanDao();
        List<SysDeviceTypeBean> sysDeviceTypeBeans = sysDeviceTypeBeanDao.queryBuilder().list();
        return sysDeviceTypeBeans;
    }

    /*删除本地所有保存的服务器的隐患设备类型数据*/
    public void deleteAllSysDeviceTypes() {
        daoSession.deleteAll(SysDeviceTypeBean.class);
    }

    /**
     * TroubleTypeBeanDao
     */
    /*保存服务器的隐患类型数据*/
    public void saveSysTroubleTypes(List<TroubleTypeBean> sysDeviceTypeBeans) {
        deleteAllSysTroubleTypes();
        TroubleTypeBeanDao troubleTypeBeanDao = daoSession.getTroubleTypeBeanDao();
        troubleTypeBeanDao.insertOrReplaceInTx(sysDeviceTypeBeans);
    }

    /*读取本地保存的隐患类型列表*/
    public List<TroubleTypeBean> getSysTroubleTypeList() {
        TroubleTypeBeanDao troubleTypeBeanDao = daoSession.getTroubleTypeBeanDao();
        List<TroubleTypeBean> sysDeviceTypeBeans = troubleTypeBeanDao.queryBuilder().list();
        return sysDeviceTypeBeans;
    }

    /*删除本地所有保存的服务器的隐患类型数据*/
    public void deleteAllSysTroubleTypes() {
        daoSession.deleteAll(TroubleTypeBean.class);
    }

    /**
     * TroubleRiskLevelBean
     */
    /*保存服务器的隐患风险等级数据*/
    public void saveSysTroubleLevels(List<TroubleRiskLevelBean> troubleLevelBeans) {
        deleteAllSysTroubleLevels();
        TroubleRiskLevelBeanDao levelBeanDao = daoSession.getTroubleRiskLevelBeanDao();
        levelBeanDao.insertOrReplaceInTx(troubleLevelBeans);
    }

    /*读取本地保存的隐患风险等级列表*/
    public List<TroubleRiskLevelBean> getSysTroubleLevelList() {
        TroubleRiskLevelBeanDao levelBeanDao = daoSession.getTroubleRiskLevelBeanDao();
        List<TroubleRiskLevelBean> levelBeans = levelBeanDao.queryBuilder().list();
        return levelBeans;
    }

    /*删除本地所有保存的服务器的隐患风险等级数据*/
    public void deleteAllSysTroubleLevels() {
        daoSession.deleteAll(TroubleRiskLevelBean.class);
    }

    /**
     * PipeTypeBean
     */
    /*保存服务器的管网类型数据*/
    public void savePipeTypes(List<PipeTypeBean> pipeTypeBeans) {
        deleteAllPipeTypes();
        PipeTypeBeanDao pipeTypeBeanDao = daoSession.getPipeTypeBeanDao();
        pipeTypeBeanDao.insertOrReplaceInTx(pipeTypeBeans);
    }

    /*读取本地保存的管网类型列表*/
    public List<PipeTypeBean> getPipeTypeList() {
        PipeTypeBeanDao pipeTypeBeanDao = daoSession.getPipeTypeBeanDao();
        List<PipeTypeBean> pipeTypeBeans = pipeTypeBeanDao.queryBuilder().list();
        return pipeTypeBeans;
    }

    /*删除本地所有保存的服务器的管网类型数据*/
    public void deleteAllPipeTypes() {
        daoSession.deleteAll(PipeTypeBean.class);
    }
}
