server:
  port: ${SERVER_PORT:8081}

spring:
  application:
    name: book-metadata-service
  datasource:
    url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_NAME:bookmetadb}?reWriteBatchedInserts=true
    username: ${DB_USERNAME:postgres}
    password: ${DB_PASSWORD:postgres}
    driver-class-name: org.postgresql.Driver
    hikari:
      maximum-pool-size: 20
      minimum-idle: 5
      connection-timeout: 30000
      idle-timeout: 600000
      max-lifetime: 1800000
  jpa:
    properties:
      hibernate:
        jdbc:
          batch_size: 1000
          batch_versioned_data: true
        order_inserts: true
        order_updates: true
        generate_statistics: false
  flyway:
    enabled: true
    locations: classpath:db/migration
    baseline-on-migrate: true
  thymeleaf:
    cache: false
  cache:
    jcache:
      provider: com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider
    cache-names:
      - public-search-buckets
      - partner-buckets
    caffeine:
      spec: maximumSize=100000,expireAfterAccess=3600s

book:
  pivot:
    default-org-id: 1

google:
  books:
    # Бесплатно: console.cloud.google.com -> APIs & Services -> Library ->
    # Books API -> Enable -> Credentials -> Create API Key. Без ключа
    # работает, но с урезанной анонимной квотой.
    api-key: ${GOOGLE_BOOKS_API_KEY:}

libgen:
  enabled: ${LIBGEN_ENABLED:false}   # юридически серая зона — осознанный opt-in
  base-url: https://libgen.li/json.php

sigla:
  # Неофициальный HTML-скрапинг sigla.ru (НБ МГУ), сайт не для автоматизированных
  # обращений — включайте осознанно.
  enabled: ${SIGLA_ENABLED:false}
  min-request-interval-ms: 2000

llm:
  fallback:
    # Результаты идут НЕ в mt_data напрямую, а в llm_suggestions на ручную
    # модерацию (LlmSuggestion, EnrichmentController.listSuggestions/approveSuggestion).
    enabled: ${LLM_FALLBACK_ENABLED:false}
    searxng-url: ${LLM_FALLBACK_SEARXNG_URL:http://localhost:8080}
    ollama-url: ${LLM_FALLBACK_OLLAMA_URL:http://localhost:11434}
    model: ${LLM_FALLBACK_MODEL:llama3.2:3b}
    confidence: ${LLM_FALLBACK_CONFIDENCE:0.3}
    timeout-seconds: ${LLM_FALLBACK_TIMEOUT_SECONDS:180}

management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics

logging:
  level:
    root: INFO
    ru.mcs.metadatabook: DEBUG
    org.hibernate.SQL: WARN

springdoc:
  api-docs:
    path: /api-docs
  swagger-ui:
    path: /swagger-ui.html
    tags-sorter: alpha
    operations-sorter: method
  default-produces-media-type: application/json

bucket4j:
  enabled: true
  cache-to-use: jcache
  filters:
    - cache-name: public-search-buckets
      url: /api/v1/(public|search)/.*
      strategy: first
      http-response-body: '{"error": "Too Many Requests", "message": "Rate limit exceeded, try again shortly"}'
      rate-limits:
        - cache-key: "getRemoteAddr()"
          bandwidths:
            - capacity: 10
              time: 10
              unit: seconds
            - capacity: 60
              time: 1
              unit: minutes