server:
  port: 18080
  shutdown: graceful
  netty:
    connection-timeout: 5s

spring:
  main:
    allow-bean-definition-overriding: true
    allow-circular-references: true
  application:
    name: ai-novel-server
  data:
    mongodb:
      uri: mongodb://mongo:123456@localhost:27017/ainoval?authSource=admin&authMechanism=SCRAM-SHA-1
      auto-index-creation: true
      password: 123456
      username: mongo
      database: ainovel
      authentication-database: admin
      map-key-dot-replacement: "#DOT#"
  webflux:
    base-path: /
  lifecycle:
    timeout-per-shutdown-phase: 30s
  rabbitmq:
    enabled: false
    host: localhost
    port: 5672
    username: guest
    password: guest
    virtual-host: /
    publisher-confirm-type: correlated
    publisher-returns: true
    dynamic: false
    listener:
      simple:
        acknowledge-mode: manual
        prefetch: 1
        concurrency: 4
        max-concurrency: 8
        auto-startup: false
        missingQueuesFatal: false
        retry:
          enabled: false
      direct:
        auto-startup: false
        missingQueuesFatal: false
    connection-timeout: 5000
    template:
      mandatory: true
      receive-timeout: 30000
      reply-timeout: 30000
  mail:
    # 阿里云邮件推送服务配置 - SSL模式（推荐）
    host: smtpdm.aliyun.com
    port: 465  # SSL端口：465，非SSL端口：25
    username: ${ALIYUN_MAIL_USERNAME:111}
    password: ${ALIYUN_MAIL_PASSWORD:111}
    protocol: smtp
    default-encoding: UTF-8
    properties:
      mail:
        smtp:
          auth: true
          starttls:
            enable: false  # SSL模式不需要STARTTLS
          ssl:
            enable: true   # 启用SSL：true(465端口)，禁用SSL：false(25端口)
            trust: smtpdm.aliyun.com
          socketFactory:
            class: javax.net.ssl.SSLSocketFactory
            fallback: false
            port: 465  # 必须与上面的port一致
          connectiontimeout: 10000
          timeout: 10000
          writetimeout: 10000

# 阿里云短信配置
aliyun:
  sms:
    access-key-id: ${ALIYUN_SMS_ACCESS_KEY_ID:your-access-key}
    access-key-secret: ${ALIYUN_SMS_ACCESS_KEY_SECRET:your-secret-key}
    sign-name: ${ALIYUN_SMS_SIGN_NAME:AINoval}
    template-code: ${ALIYUN_SMS_TEMPLATE_CODE:SMS_123456}

# 应用配置
app:
  name: AINoval

logging:
  level:
    root: INFO
    com.ainovel: DEBUG
    org.springframework.data.mongodb: INFO
    org.springframework.web: INFO
    reactor.netty: INFO
    com.ainovel.server: DEBUG
    com.ainovel.server.task: INFO
    org.springframework.amqp: INFO
  request: true
  pattern:
    console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) [%X{traceId:-}] [%X{userId:-}] [%thread] %logger{36} - %msg%n"

management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics,prometheus,jmx
    jmx:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: when-authorized
    jmx:
      enabled: true
  health:
    mail:
      enabled: false
  jmx:
    enabled: true
  prometheus:
    metrics:
      export:
        enabled: true
  otlp:
    metrics:
      export:
        enabled: false  # 开发环境禁用OTLP，只在生产环境启用
  metrics:
    tags:
      application: ${spring.application.name}
    distribution:
      percentiles-histogram:
        "[tasks.execution.time]": true
      percentiles:
        "[tasks.execution.time]": [0.5, 0.95, 0.99]
      slo:
        "[tasks.execution.time]": [1000ms, 5000ms, 10000ms]

# 自定义配置
ainovel:
  security:
    jwt:
      # 统一引用 JWT_SECRET 环境变量，保持与 dev/prod 一致
      secret-key: ${JWT_SECRET:changeme_in_production_environment}
      expiration-time: 86400000  # 24小时，单位毫秒
      refresh-token-expiration: 604800000  # 7天，单位毫秒
  performance:
    virtual-threads:
      enabled: true
    monitoring:
      enabled: true
  version-control:
    enabled: true
    auto-save-history: true
    max-history-count: 20
  mail:
    # 邮件服务测试配置
    test-on-startup: ${MAIL_TEST_ON_STARTUP:true}  # 是否在启动时测试邮件配置
    test-email: ${MAIL_TEST_EMAIL:}  # 默认测试邮箱，启动时会发送测试邮件
  storage:
    default-provider: alioss
    covers-path: covers
    # 是否在启动时测试OSS连接
    test-on-startup: true
    # 阿里云OSS配置
    aliyun:
      endpoint: https://oss-cn-shanghai.aliyuncs.com
      access-key-id: ${ALIYUN_OSS_ACCESS_KEY_ID}
      access-key-secret: ${ALIYUN_OSS_ACCESS_KEY_SECRET}
      bucket-name: ${ALIYUN_OSS_BUCKET_NAME}
      base-url: ${ALIYUN_OSS_BASE_URL}
      region: cn-shanghai
  ai:
    default-prompts:
      scene-to-summary: "请根据以下小说场景内容，生成一段简洁的摘要。\n场景内容:\n{input}\n参考信息:\n{context}"
      summary-to-scene: "请根据以下摘要/大纲，结合参考信息，生成一段详细的小说场景。\n摘要/大纲:\n{input}\n参考信息:\n{context}"
    rag:
      # RAG检索相关配置
      retrieval-k: 5
    # Resilience配置
    resilience:
      timeout:
        duration: 30s
      retry:
        max-attempts: 3
        backoff:
          initial-delay: 1s
          multiplier: 2
    # 各AI功能开关
    features:
      setting-tree-generation:
        # 启动时是否初始化 SETTING_TREE_GENERATION 的提示词/策略模板
        init-on-startup: false
  registration:
    quick-enabled: ${REGISTRATION_QUICK_ENABLED:true}
    email-enabled: ${REGISTRATION_EMAIL_ENABLED:false}
    phone-enabled: ${REGISTRATION_PHONE_ENABLED:false}

# 向量存储配置
vectorstore:
  chroma:
    enabled: false
    url: http://localhost:18000
    collection: ainovel
    use-random-collection: false
    reuse-collection: true

# 代理配置
proxy:
  enabled: true
  host: localhost
  port: 6888


jwt:
  # 统一使用环境变量 JWT_SECRET，提供开发默认值
  secret: ${JWT_SECRET:aiNovelSecretKey12345678901234567890}
  expiration: 86400000
  refresh-expiration: 604800000
payment:
  wechat:
    mch-id: ${WECHAT_MCH_ID:}
    app-id: ${WECHAT_APP_ID:}
    api-v3-key: ${WECHAT_API_V3_KEY:}
    merchant-serial-no: ${WECHAT_MCH_SERIAL_NO:}
    merchant-private-key-pem: ${WECHAT_MCH_PRIVATE_KEY_PEM:}
    platform-public-key-pem: ${WECHAT_PLATFORM_PUBLIC_KEY_PEM:}
    notify-url: ${WECHAT_NOTIFY_URL:http://localhost:18080/api/v1/payments/notify/WECHAT}
    sandbox: ${WECHAT_SANDBOX:false}
  alipay:
    app-id: ${ALIPAY_APP_ID:}
    merchant-private-key-pem: ${ALIPAY_MERCHANT_PRIVATE_KEY_PEM:}
    merchant-public-key-pem: ${ALIPAY_MERCHANT_PUBLIC_KEY_PEM:}
    alipay-public-key-pem: ${ALIPAY_PUBLIC_KEY_PEM:}
    notify-url: ${ALIPAY_NOTIFY_URL:http://localhost:18080/api/v1/payments/notify/ALIPAY}
    sandbox: ${ALIPAY_SANDBOX:false}

ai:
  model:
    default: gpt-3.5-turbo
    temperature: 0.7
    max-tokens: 8192

jasypt:
  encryptor:
    password: AINoval_Secure_Encryption_Key_2025
    algorithm: PBEWITHHMACSHA512ANDAES_256
    iv-generator-classname: org.jasypt.iv.RandomIvGenerator

# 限流器配置
task:
  transport: local
  local:
    concurrency: 4
  # 限流配置
  ratelimiter:
    # 限流器类型: memory (基于内存) 或 redis (分布式)
    type: memory
    
    # 限流维度配置
    dimensions:
      default: USER_PROVIDER_MODEL  # 默认：用户+供应商+模型
      gemini: GLOBAL               # Gemini：全局限流（免费层共享配额）
      sensitive_tasks: HYBRID      # 敏感任务：最细粒度限流
      high_performance: PROVIDER_MODEL  # 高性能：供应商+模型
    
    # 默认限流配置
    default:
      # 每秒许可数量 (QPS)
      rate: 10.0
      # 突发容量 (令牌桶最大容量)
      burstCapacity: 20
      # 获取许可的默认超时时间(毫秒)
      defaultTimeoutMillis: 5000
      # 默认限流维度
      dimension: USER_PROVIDER_MODEL
    # 各AI提供商或模型的特定限流配置
    providers:
      # Gemini特殊配置 - 应对200次/天限制
      gemini:
        strategy: CONSERVATIVE  # 保守策略
        dimension: GLOBAL       # 全局维度限流（免费层共享配额）
        rate: 2              # 每秒0.2个请求 (约180次/天)
        burstCapacity: 2       # 突发容量1
        dailyLimit: 2000000       # 日限额200次
        safetyBuffer: 20       # 安全缓冲20次
        retryStrategy: EXPONENTIAL_BACKOFF  # 4倍指数退避
        maxRetryAttempts: 3    # 最大重试3次（降低以避免长时间等待）
        defaultTimeoutMillis: 20000  # 20秒超时（降低以更快失败并重试）
        
      # OpenAI标准配置  
      openai:
        strategy: STANDARD     # 标准策略
        dimension: USER_PROVIDER_MODEL  # 用户+供应商+模型维度
        rate: 5.0             # 每秒5个请求
        burstCapacity: 10     # 突发容量10
        retryStrategy: LINEAR_BACKOFF
        maxRetryAttempts: 3
        defaultTimeoutMillis: 3000
        
      # Anthropic激进配置
      anthropic:
        strategy: AGGRESSIVE   # 激进策略
        dimension: USER_PROVIDER_MODEL  # 用户+供应商+模型维度
        rate: 3.0             # 每秒3个请求
        burstCapacity: 6      # 突发容量6
        retryStrategy: LINEAR_BACKOFF
        maxRetryAttempts: 2
        defaultTimeoutMillis: 3000
        
      # GPT-4特殊限制
      gpt-4:
        strategy: CONSERVATIVE # 保守策略，GPT-4通常限制更严格
        rate: 2.0             # 每秒2个请求
        burstCapacity: 4      # 突发容量4
        retryStrategy: EXPONENTIAL_BACKOFF
        maxRetryAttempts: 4
        defaultTimeoutMillis: 10000
        
      # 其他供应商自适应配置
      openrouter:
        strategy: ADAPTIVE     # 自适应策略
        rate: 8.0
        burstCapacity: 15
        retryStrategy: INTELLIGENT_BACKOFF
        maxRetryAttempts: 4
        defaultTimeoutMillis: 5000
        
      siliconflow:
        strategy: STANDARD
        rate: 10.0
        burstCapacity: 20
        retryStrategy: LINEAR_BACKOFF
        maxRetryAttempts: 3
        defaultTimeoutMillis: 5000
  # 重试配置
  retry:
    maxAttempts: 5
    initialDelayMillis: 5000
    maxDelayMillis: 3600000 # 1 hour
    backoffFactor: 2.0
    jitterFactor: 0.1
    # 添加缺失的 delays 配置，使用默认值
    delays: 15000,60000,300000
  # 关闭配置
  shutdown:
    awaitTerminationTimeout: PT30S # ISO-8601 duration
