spring:
  application:
    name: pharmacopoeia-ai
  datasource:
    url: jdbc:postgresql://localhost:5432/pharmacopoeia
    username: postgres
    password: pharma2025
    driver-class-name: org.postgresql.Driver
    hikari:
      maximum-pool-size: 20
      minimum-idle: 5
      connection-timeout: 30000
      max-lifetime: 1800000
      idle-timeout: 600000
      connection-test-query: SELECT 1
      pool-name: PharmaHikariCP

  jpa:
    hibernate:
      ddl-auto: none
    show-sql: false
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
        format_sql: true

  data:
    redis:
      host: localhost
      port: 6379
      lettuce:
        pool:
          max-active: 20
          max-idle: 10
          min-idle: 5
          max-wait: 3000ms
      timeout: 3000ms

  jackson:
    serialization:
      write-dates-as-timestamps: false

  servlet:
    multipart:
      max-file-size: 50MB
      max-request-size: 55MB

  task:
    execution:
      pool:
        core-size: 2
        max-size: 4
        queue-capacity: 100
        thread-name-prefix: task-
      shutdown:
        await-termination: true
        await-termination-period: 60s

server:
  port: 9000
  tomcat:
    threads:
      max: 200
      min-spare: 10
    accept-count: 100
    max-connections: 8192
    max-http-form-post-size: 55MB
    max-http-header-size: 64KB
    connection-timeout: 20000ms
    keep-alive-timeout: 60000ms

# ============================================
# Qwen API 配置
# ============================================
qwen:
  api-key: ${QWEN_API_KEY:}
  base-url: https://dashscope.aliyuncs.com/compatible-mode/v1
  model: qwen3.7-flash
  max-tokens: 2048
  temperature: 0.0
  # 视觉模型（图片分析+OCR）
  # 多模态模型（图片/视频分析，原生 API）
  vl-model: qwen3.7-plus
  multimodal-url: https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
  enable-web-search: true
  # qwen3 思考（reasoning）模式：默认开（兜底路径用）；L1 药名直取不经过 LLM，结论小调用单独关思考
  enable-thinking: true
  # 嵌入模型
  embedding-model: text-embedding-v3
  embedding-url: https://dashscope.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding
  embedding-dim: 1024

# ============================================
# 鉴权
# ============================================
auth:
  enabled: false       # true=上线后需要 JWT token
  admin-token: ""     # 运营端管理 token（与 JWT 无关，单独配置）

# ============================================
# JWT
# ============================================
jwt:
  secret: YourSuperSecretKeyForJWTTokenGenerationMustBeAtLeast256BitsLong!!
  expiration: 86400000  # 24小时 (ms)

# ============================================
# 微信小程序
# ============================================
wechat:
  app-id: ${WECHAT_APPID:}
  secret: ${WECHAT_SECRET:}

# ============================================
# 百炼（DashScope）API 全局限流
# 控制后端 → 百炼的总调用量，与用户侧限流独立
# 最终是否限制、限制多少由客户确认后配置
# ============================================
dashscope:
  rate-limit:
    enabled: false   # 客户确认后改为 true
    per-minute: 100
    per-hour: 2000
    per-day: 50000
# ============================================
# 限流
# ============================================
rate-limit:
  per-minute: 60         # 每 IP 每分钟最多 20 次 chat 请求（Caffeine 滑动窗口，窗口滑过自动恢复）
  analytics-per-minute: 600  # 埋点写入 /api/v1/analytics/events 限流（多系统调用，给大）
  per-hour: 999999    # 极大=不限（预留，当前未启用）
  per-day: 999999     # 极大=不限（预留，当前未启用）

logging:
  level:
    com.pharmacopoeia: INFO
    org.springframework.web: WARN
    org.springframework.security: INFO
  file:
    path: ${LOG_DIR:/var/log/pharmacopoeia}
