server:
  port: 8080

spring:
  application:
    name: hzhub-gateway

  # Redis 配置（限流用）
  data:
    redis:
      host: ${REDIS_HOST:localhost}
      port: ${REDIS_PORT:6379}
      password: ${REDIS_PASSWORD:}

  cloud:
    gateway:
      server:
        webflux:
          routes:
            # AI服务
            - id: hzhub-ai
              uri: http://${AI_HOST:localhost}:${AI_PORT:6039}
              predicates:
                - Path=/ai/**
              filters:
                - StripPrefix=1
              metadata:
                response-timeout: 86400000  # 24h，AI SSE 流式响应需要
                connect-timeout: 5000

            # MCP工具管理（AI服务，保留/mcp前缀以匹配控制器映射）
            - id: hzhub-mcp
              uri: http://${AI_HOST:localhost}:${AI_PORT:6039}
              predicates:
                - Path=/mcp/**
              metadata:
                response-timeout: 30000
                connect-timeout: 5000

            # ERP服务（保留/erp前缀以匹配后端控制器映射）
            - id: hzhub-erp
              uri: http://${ERP_HOST:localhost}:${ERP_PORT:8082}
              predicates:
                - Path=/erp/**
              metadata:
                response-timeout: 30000
                connect-timeout: 3000

            # AI 服务的 /system/* 端点（模型/会话/消息/知识库等）
            - id: hzhub-ai-system
              uri: http://${AI_HOST:localhost}:${AI_PORT:6039}
              predicates:
                - Path=/system/model/**,/system/provider/**,/system/session/**,/system/message/**,/system/graphInstance/**,/system/info/**,/system/graphSegment/**,/system/attach/**,/system/fragment/**
              metadata:
                response-timeout: 30000
                connect-timeout: 5000

            # 系统服务（独立 hzhub-system 服务，warm-flow 审批流必须放在 aiflow 之前）
            - id: hzhub-system
              uri: http://${SYSTEM_HOST:localhost}:${SYSTEM_PORT:8083}
              predicates:
                - Path=/system/user/**,/system/role/**,/system/menu/**,/system/dept/**,/system/post/**,/system/dict/**,/system/tenant/**,/system/config/**,/system/notice/**,/system/client/**,/system/social/**,/monitor/**,/auth/**,/resource/**,/workflow/definition/**,/workflow/category/**,/workflow/task/**,/workflow/instance/**,/workflow/spel/**,/workflow/leave/**,/tool/**,/chat/config/**,/wecom/**
              metadata:
                response-timeout: 30000
                connect-timeout: 5000

            # CRM服务（hzhub-system 服务，线索管理、经销商管理）
            - id: hzhub-crm
              uri: http://${SYSTEM_HOST:localhost}:${SYSTEM_PORT:8083}
              predicates:
                - Path=/crm/**
              filters:
                - StripPrefix=1
              metadata:
                response-timeout: 30000
                connect-timeout: 5000

            # AI 工作流（aiflow 模块，catch-all 必须放在最后）
            - id: hzhub-ai-workflow
              uri: http://${AI_HOST:localhost}:${AI_PORT:6039}
              predicates:
                - Path=/workflow/**,/admin/workflow/**
              metadata:
                response-timeout: 86400000  # aiflow 可能需要长时间运行
                connect-timeout: 5000

          # 全局默认过滤器
          default-filters:
            - name: RequestRateLimiter
              args:
                redis-rate-limiter.replenishRate: 10
                redis-rate-limiter.burstCapacity: 20
                key-resolver: "#{@ipKeyResolver}"

          # 跨域配置（由 CorsConfig.java 处理，globalcors 不适用于 Webflux 路由转发）

# Sa-Token JWT 密钥（与后端服务共享，必须 >= 256 bits / 32 字节）
sa-token:
  jwt-secret-key: ${JWT_SECRET:Om1fovSeKIA1oLIoHdDPMF-trbqbrPQoDS3H4u1xoRY}

# Spring Boot Admin 客户端配置
spring.boot.admin:
  client:
    url: ${ADMIN_URL:http://localhost:9090/admin}
    username: ${ADMIN_USER:ruoyi}
    password: ${ADMIN_PASSWORD:123456}
    instance:
      service-host-type: IP

# Actuator 监控配置
management:
  endpoints:
    web:
      exposure:
        include: health,prometheus,gateway,env,metrics,loggers,info
  endpoint:
    health:
      show-details: always
  metrics:
    tags:
      application: ${spring.application.name}

# 日志
logging:
  level:
    org.hzhub.gateway: info
