# -*- coding:utf-8 -*-
"""
@Author  : xuxingchen
@Contact : xuxingchen@sinochem.com
@Desc    : 
"""
import os
import json

import logger


ENV_TYPE = int(os.environ.get("ENV_TYPE", 3))  # 0: 本地环境，1：测试容器环境，2: 生产容器环境，3: 本地开发环境

SLEEP_TIME = 0.03 if ENV_TYPE != 0 else 1  # 循环等待时间，正式环境30ms检测一次，开发环境1000ms检测一次
TIMEOUT_SECOND = 5 if ENV_TYPE != 0 else 10  # 等待超时时间，正式环境5s，开发环境10s
DB_PATH = "./data/_meian.db" if ENV_TYPE != 2 else "./data/meian.db"
GATEWAY_CONFIG_PATH = "./data/_gateways.json" if ENV_TYPE != 2 else "./data/gateways.json"
CONFIG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "config.json")
ENV_INFO = json.load(open(CONFIG_PATH, "r", encoding="utf8"))
BACKEND_ID = "320566c*********200"
BACKEND_SECRET = "807aa9d**********b1188d85ff6"
BACKEND_URL = "https://iot-api.******.com" if ENV_TYPE == 2 else "https://iot-api-test.********.com"

LOGGER_DEBUG = os.environ.get("LOGGER_DEBUG", ENV_INFO[ENV_TYPE]["LOGGER_DEBUG"])
logger.DEBUG = False if LOGGER_DEBUG.upper() == "FALSE" else True
DEBUG = logger.DEBUG
logger.LOGGER_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "run.log")

# project_code - project_id
with open(GATEWAY_CONFIG_PATH, "r", encoding="utf8") as f:
    GATEWAY_CONFIG = json.load(f)

# 0 mqtt
BROKER_0_HOST = os.environ.get("BROKER_0_HOST", ENV_INFO[ENV_TYPE]["BROKER_0_HOST"])
BROKER_0_PORT = int(os.environ.get("BROKER_0_PORT", ENV_INFO[ENV_TYPE]["BROKER_0_PORT"]))
BROKER_0_API_PORT = int(os.environ.get("BROKER_0_API_PORT", ENV_INFO[ENV_TYPE]["BROKER_0_API_PORT"]))
BROKER_0_SSL = False
BROKER_0_USERNAME = os.environ.get("BROKER_0_USERNAME", ENV_INFO[ENV_TYPE]["BROKER_0_USERNAME"])
BROKER_0_PASSWD = os.environ.get("BROKER_0_PASSWD", ENV_INFO[ENV_TYPE]["BROKER_0_PASSWD"])
BROKER_0_API_KEY = os.environ.get("BROKER_0_API_KEY", ENV_INFO[ENV_TYPE]["BROKER_0_API_KEY"])
BROKER_0_API_SECRET = os.environ.get("BROKER_0_API_SECRET", ENV_INFO[ENV_TYPE]["BROKER_0_API_SECRET"])

# 1 aiot
BROKER_1_HOST = os.environ.get("BROKER_1_HOST", ENV_INFO[ENV_TYPE]["BROKER_1_HOST"])
BROKER_1_PORT = int(os.environ.get("BROKER_1_PORT", ENV_INFO[ENV_TYPE]["BROKER_1_PORT"]))
BROKER_1_SSL = False
