spring:
  datasource:
    url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/storycove}
    username: ${SPRING_DATASOURCE_USERNAME:storycove}
    password: ${SPRING_DATASOURCE_PASSWORD:password}
    driver-class-name: org.postgresql.Driver
    hikari:
      connection-timeout: 60000  # 60 seconds
      idle-timeout: 300000       # 5 minutes
      max-lifetime: 1800000      # 30 minutes
      maximum-pool-size: 20
  
  jpa:
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
        format_sql: true
    show-sql: false
  
  servlet:
    multipart:
      max-file-size: 4096MB  # 4GB for large backup restore
      max-request-size: 4150MB  # Slightly higher to account for form data

  jackson:
    serialization:
      write-dates-as-timestamps: false
    deserialization:
      adjust-dates-to-context-time-zone: false

server:
  port: 8080
  tomcat:
    max-http-request-size: 4200MB  # Tomcat HTTP request size limit (4GB + overhead)

storycove:
  app:
    public-url: ${STORYCOVE_PUBLIC_URL:http://localhost:6925}
  cors:
    allowed-origins: ${STORYCOVE_CORS_ALLOWED_ORIGINS:http://localhost:3000,http://localhost:6925}
  jwt:
    secret: ${JWT_SECRET}  # REQUIRED: Must be at least 32 characters, no default for security
    expiration: 86400000  # 24 hours (access token)
    refresh-expiration: 1209600000  # 14 days (refresh token)
  auth:
    password: ${APP_PASSWORD}  # REQUIRED: No default password for security
  search:
    engine: solr  # Apache Solr search engine
    # Cron for the nightly full reindex (stories + authors + collections). Default: 3 AM daily.
    # Set to "-" to disable. Override via SEARCH_NIGHTLY_REINDEX_CRON env var.
    nightly-reindex-cron: ${SEARCH_NIGHTLY_REINDEX_CRON:0 0 3 * * ?}
    # How often (ms) to reindex authors to refresh derived stats (storyCount, averageRating).
    author-reindex-interval: ${SEARCH_AUTHOR_REINDEX_INTERVAL:7200000}
  solr:
    # Connection settings
    url: ${SOLR_URL:http://solr:8983/solr}
    username: ${SOLR_USERNAME:}
    password: ${SOLR_PASSWORD:}

    # Core configuration
    cores:
      stories: ${SOLR_STORIES_CORE:storycove_stories}
      authors: ${SOLR_AUTHORS_CORE:storycove_authors}

    # Connection settings
    connection:
      timeout: ${SOLR_CONNECTION_TIMEOUT:30000}  # 30 seconds
      socket-timeout: ${SOLR_SOCKET_TIMEOUT:60000}  # 60 seconds
      max-connections-per-route: ${SOLR_MAX_CONN_PER_ROUTE:10}
      max-connections-total: ${SOLR_MAX_CONN_TOTAL:30}
      retry-on-failure: ${SOLR_RETRY_ON_FAILURE:true}
      max-retries: ${SOLR_MAX_RETRIES:3}

    # Query settings
    query:
      default-rows: ${SOLR_DEFAULT_ROWS:10}
      max-rows: ${SOLR_MAX_ROWS:5000}
      default-operator: ${SOLR_DEFAULT_OPERATOR:AND}
      highlight: ${SOLR_ENABLE_HIGHLIGHT:true}
      facets: ${SOLR_ENABLE_FACETS:true}

    # Commit settings
    commit:
      soft-commit: ${SOLR_SOFT_COMMIT:true}
      commit-within: ${SOLR_COMMIT_WITHIN:1000}  # 1 second
      wait-searcher: ${SOLR_WAIT_SEARCHER:false}

    # Health and monitoring
    health:
      check-interval: ${SOLR_HEALTH_CHECK_INTERVAL:30000}  # 30 seconds
      slow-query-threshold: ${SOLR_SLOW_QUERY_THRESHOLD:5000}  # 5 seconds
      enable-metrics: ${SOLR_ENABLE_METRICS:true}
  images:
    storage-path: ${IMAGE_STORAGE_PATH:/app/images}
  automatic-backup:
    dir: ${AUTOMATIC_BACKUP_DIR:/app/automatic-backups}

management:
  endpoints:
    web:
      exposure:
        include: health,info,prometheus
  endpoint:
    health:
      show-details: when-authorized
      show-components: always
  health:
    solr:
      enabled: ${SOLR_HEALTH_ENABLED:true}

logging:
  level:
    com.storycove: ${LOG_LEVEL:INFO}  # Use INFO for production, DEBUG for development
    org.springframework.security: WARN  # Reduce security logging
    org.springframework.web: WARN
    org.hibernate.SQL: ${SQL_LOG_LEVEL:WARN}  # Control SQL logging separately