package xn.hxp.room.tool;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;

import xn.hxp.room.RoomTool;
import xn.hxp.room.bean.DeviceInfo;
import xn.hxp.room.dao.DeviceInfoDao;
import xn.hxp.util.Tool;

public enum DeviceInfoTool {
    INSTANCE;

    private DeviceInfoDao deviceInfoDao;

    DeviceInfoTool() {
        deviceInfoDao = RoomTool.getInstance().deviceInfoDao();
        init();
    }

    private void init() {
        DeviceInfo deviceInfo = deviceInfoDao.getDeviceInfo();
        if (null == deviceInfo) {
            deviceInfo = new DeviceInfo();
            deviceInfo.setBaseUrl(AppUtils.isAppDebug() ? "http://192.168.1.8" : "http://172.16.0.65");
            deviceInfo.setAdminPwd("hxp");
            deviceInfo.setIp(NetworkUtils.getIPAddress(true));
            deviceInfo.setSn(Tool.INSTANCE.getSerialNumber());
            deviceInfo.setFrontCamera(true);
            deviceInfoDao.insert(deviceInfo);
        }
    }

    public DeviceInfo getDeviceInfo() {
        return deviceInfoDao.getDeviceInfo();
    }

    public void insert(DeviceInfo deviceInfo) {
        deviceInfoDao.insert(deviceInfo);
    }

}
