# -*- coding: utf-8 -*-
"""
配置中心 - 统一管理路径、常量
"""
import os
from pathlib import Path
from dotenv import load_dotenv

load_dotenv()

# ========== 项目路径 ==========
ROOT = Path(__file__).resolve().parent.parent
LOG_DIR = ROOT / "logs"
RESULTS_DIR = Path(os.getenv("RESULT_IMAGE_DIR", str(ROOT / "results")))
CONFIG_DIR = ROOT / "config"
CUSTOMER_DB_DIR = ROOT / "customer_db"

# ========== 轻简 ==========
QINGJIAN_WS_URI = os.getenv("QINGJIAN_WS_URI", "ws://127.0.0.1:9528")

# ========== 企微 ==========
WECHAT_WEBHOOK = os.getenv("WECHAT_WEBHOOK", "")

# ========== 日志 ==========
LOG_MAX_BYTES = int(os.getenv("LOG_MAX_BYTES", "10")) * 1024 * 1024  # 默认 10MB
LOG_BACKUP_COUNT = int(os.getenv("LOG_BACKUP_COUNT", "7"))

# ========== 图片队列 ==========
IMAGE_QUEUE_MAX_CONCURRENT = int(os.getenv("IMAGE_QUEUE_MAX_CONCURRENT", "2"))
IMAGE_QUEUE_MAX_SIZE = int(os.getenv("IMAGE_QUEUE_MAX_SIZE", "20"))

# ========== 健康检查 ==========
HEALTH_CHECK_INTERVAL = int(os.getenv("HEALTH_CHECK_INTERVAL", "60"))  # 秒
HEALTH_CHECK_WECHAT_PING = os.getenv("HEALTH_CHECK_WECHAT_PING", "false").lower() in ("1", "true", "yes")
HEALTH_CHECK_STARTUP_GRACE = int(os.getenv("HEALTH_CHECK_STARTUP_GRACE", "15"))
HEALTH_CHECK_QINGJIAN_ALERTS_ENABLED = os.getenv("HEALTH_CHECK_QINGJIAN_ALERTS_ENABLED", "false").lower() in ("1", "true", "yes")

# ========== 功能开关 ==========
IMAGE_MODULE_ENABLED = os.getenv("IMAGE_MODULE_ENABLED", "false").lower() in ("1", "true", "yes")

# ========== 防抖配置 ==========
MESSAGE_DEBOUNCE_SECONDS = int(os.getenv("MESSAGE_DEBOUNCE_SECONDS", "8"))
OUTBOUND_PER_CUSTOMER_COOLDOWN_SECONDS = int(os.getenv("OUTBOUND_PER_CUSTOMER_COOLDOWN_SECONDS", "5"))

# ========== AI 上下文加载 ==========
CHAT_CONTEXT_LIMIT = int(os.getenv("CHAT_CONTEXT_LIMIT", "30"))
CHAT_CONTEXT_TRUNCATE_LEN = int(os.getenv("CHAT_CONTEXT_TRUNCATE_LEN", "160"))

# ========== 报价底线 ==========
MIN_PRICE_FLOOR = int(os.getenv("MIN_PRICE_FLOOR", "15"))
MAX_SERVICE_SIZE_LONGEST_METERS = float(os.getenv("MAX_SERVICE_SIZE_LONGEST_METERS", "10"))
MAX_SERVICE_SIZE_AREA_SQM = float(os.getenv("MAX_SERVICE_SIZE_AREA_SQM", "20"))

# ========== 批量报价/自动处理 ==========
BATCH_MAX_IMAGES = int(os.getenv("BATCH_MAX_IMAGES", "12"))  # 单次最多处理图片数
BATCH_ANALYZE_CONCURRENCY = int(os.getenv("BATCH_ANALYZE_CONCURRENCY", "3"))  # 批量识别并发数

# ========== 灰度开关 ==========
FEATURE_BATCH_QUOTE_ENABLED = os.getenv("FEATURE_BATCH_QUOTE_ENABLED", "true").lower() in ("1", "true", "yes")
FEATURE_BATCH_QUOTE_PERCENT = int(os.getenv("FEATURE_BATCH_QUOTE_PERCENT", "100"))  # 0-100
FEATURE_BATCH_QUOTE_SHOPS = os.getenv("FEATURE_BATCH_QUOTE_SHOPS", "")  # 逗号分隔 acc_id 白名单，空=全量

# ========== 系统客服询单识别 ==========
SYSTEM_INQUIRY_ENABLED = os.getenv("SYSTEM_INQUIRY_ENABLED", "true").lower() in ("1", "true", "yes")
SYSTEM_INQUIRY_DEFAULT_ACTION = os.getenv("SYSTEM_INQUIRY_DEFAULT_ACTION", "silent").strip().lower()
SYSTEM_INQUIRY_DEFAULT_REPLY = os.getenv(
    "SYSTEM_INQUIRY_DEFAULT_REPLY",
    "您好，这边已收到询单消息，稍后由人工客服跟进处理。",
)
SYSTEM_INQUIRY_SHOPS = os.getenv("SYSTEM_INQUIRY_SHOPS", "")  # 逗号分隔店铺白名单，空=全店铺
SYSTEM_INQUIRY_RULES_FILE = os.getenv(
    "SYSTEM_INQUIRY_RULES_FILE",
    str(CONFIG_DIR / "system_inquiry_rules.json"),
)
