server:
  port: 8081

spring:
  application:
    name: book-metadata-service
  datasource:
    url: jdbc:postgresql://localhost:5439/bookmetadb?reWriteBatchedInserts=true
    username: postgres
    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
  api:
    # Временный статичный ключ на старте. Позже заменить на таблицу api_keys.
    static-api-key: dev-local-key-change-me
    public-api-key: public-books-2026-change-me

google:
  books:
    # Получить бесплатно: console.cloud.google.com -> New Project ->
    # APIs & Services -> Library -> найти "Books API" -> Enable ->
    # Credentials -> Create Credentials -> API Key. Карта не требуется.
    api-key: AIzaSyDM02ULcgbyuTLRZPsbUIueKHs-g81KMDw

libgen:
  enabled: false   # осознанный opt-in — юридически серая зона, включайте сами
  base-url: https://libgen.li/json.php

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

llm:
  fallback:
    # ВКЛЮЧЕНО для тестирования. Результаты идут НЕ в mt_data напрямую,
    # а в таблицу llm_suggestions на ручную модерацию (см. LlmSuggestion,
    # EnrichmentController.listSuggestions/approveSuggestion).
    enabled: true
    searxng-url: http://localhost:8091
    ollama-url: http://192.168.30.55:11434
    # llama3.2:3b — модель, проверенная на этой машине (8 ГБ RAM) без OOM.
    # На сервере с 16 ядрами/100 ГБ RAM смените на более крупную (qwen2.5:14b и т.п.).
    model: qwen2.5:32b
    confidence: 0.3
    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