# -*- coding:utf-8 -*-
"""
@Author  : xuxingchen
@Contact : xuxingchen@sinochem.com
@Desc    : 根据实际情况动态变化的配置
"""
import os
from utils import logger
from utils.misc import get_ip_address

VERSION = "0.0.0.1"
PREFIX_PATH = "/api/v1"
DB_PATH = "./data/SCLP.db"
FACES_DIR_PATH = "data/FaceImages"
SUB_PATH = "faces"

ENV_FLAG = os.getenv("ENV_FLAG", "DEPLOY")
if_name = "WLAN" if os.name != "posix" else "enp1s0" if ENV_FLAG != "WJ14P" else "wlp2s0"
LAN_IP, _ = get_ip_address(if_name)
if ENV_FLAG == "DEPLOY":
    if "10.59.246" in LAN_IP:
        ENV_FLAG = "LAB"
    if "192.168.1" in LAN_IP:
        ENV_FLAG = "X13"
SLEEP_TIME = 0.03  # mqtt publish后的循环等待返回时间，30ms检测一次
TIMEOUT_SECOND = 30  # 等待超时时间，3s

LOGGER_DEBUG = os.environ.get("LOGGER_DEBUG", "True")
logger.DEBUG = False if LOGGER_DEBUG.lower() == "false" else True
logger.LOGGER_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "run.log")

LOCAL_IP = "127.0.0.1"
ENV_CONFIG = {
    "B760M": {"HOST": "b760m.langzihan.top", "PORT": 9680, "BROKER_HOST": LOCAL_IP, "BROKER_PORT": 1883},
    "M5": {"HOST": "sclp.langzihan.top", "PORT": 80, "BROKER_HOST": LOCAL_IP, "BROKER_PORT": 1883},
    "X13": {"HOST": LOCAL_IP, "PORT": 9680, "BROKER_HOST": "intranet.b760m.langzihan.top", "BROKER_PORT": 1883},
    "WJ14P": {"HOST": LOCAL_IP, "PORT": 9680, "BROKER_HOST": "intranet.b760m.langzihan.top", "BROKER_PORT": 1883},
    "LAB": {"HOST": "10.59.246.170", "PORT": 9680, "BROKER_HOST": "10.59.246.161", "BROKER_PORT": 31883},
    "DEPLOY": {"HOST": "10.59.246.170", "PORT": 9680, "BROKER_HOST": "10.59.246.161", "BROKER_PORT": 31883},
}
APP_HOST = ENV_CONFIG[ENV_FLAG]["HOST"]
APP_PORT = ENV_CONFIG[ENV_FLAG]["PORT"]
IMAGE_SERVER_PORT = APP_PORT + 1

BROKER_HOST = ENV_CONFIG[ENV_FLAG]["BROKER_HOST"]
BROKER_PORT = ENV_CONFIG[ENV_FLAG]["BROKER_PORT"]
BROKER_USERNAME = "test@sclp"
BROKER_PASSWD = "test@sclp"

AUTO_CALLBACK = False if ENV_FLAG == "LAB" else True
