spring:
  application:
    name: eventhub-ingestion-service
  datasource:
    url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_NAME:eventhub}
    username: ${DB_USER:}
    password: ${DB_PASSWORD:}
    hikari:
      maximum-pool-size: 16
      minimum-idle: 4
      connection-timeout: 30000
      validation-timeout: 5000
      idle-timeout: 300000
      keepalive-time: 120000
      max-lifetime: 540000
  flyway:
    enabled: true
    default-schema: eventhub
    schemas: eventhub
    create-schemas: true

logging:
  file:
    name: ${EVENTHUB_LOG_FILE:logs/eventhub-ingestion-service.log}
  logback:
    rollingpolicy:
      max-file-size: ${EVENTHUB_LOG_MAX_FILE_SIZE:50MB}
      max-history: ${EVENTHUB_LOG_MAX_HISTORY:14}
      total-size-cap: ${EVENTHUB_LOG_TOTAL_SIZE_CAP:1GB}

server:
  port: 8085

camel:
  springboot:
    name: eventhub-ingestion-camel
    main-run-controller: true

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

eventhub:
  batch:
    completion-size: 5000
    completion-timeout: 5s
    queue-size: 10000
    concurrent-consumers: 4
    block-when-full: true
    queue-offer-timeout: 5m
  tachograph:
    default-chunk-days: 1
    occurred-at-overlap: 7d
    sync-vehicle-registrations-on-master-data-update: true

    # Set TACHOGRAPH_DB_JDBC_URL to enable JdbcTachographExtractionBatchExecutor.
    datasource:
      jdbc-url: ${TACHOGRAPH_DB_JDBC_URL:}
      username: ${TACHOGRAPH_DB_USER:}
      password: ${TACHOGRAPH_DB_PASSWORD:}
      driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

    # Enables the scheduler that regularly triggers configured tachograph import plans.
    # Default is safe: no scheduled import starts unless explicitly enabled.
    scheduler-enabled: false
    scheduler-poll-interval-ms: 3600000

    # PLAN_ONLY creates import_run + planned extraction packages.
    # EXECUTE also invokes the configured TachographExtractionBatchExecutor.
    scheduler-trigger-mode: EXECUTE

    # JDBC extraction handoff mode:
    # SYNC_DIRECT = persist controlled JDBC batches directly, cursor-safe default.
    # CAMEL_ROUTE = persist the same controlled batches through direct:eventhub-batch-persist-input.
    jdbc-extraction-ingest-mode: ${TACHOGRAPH_JDBC_EXTRACTION_INGEST_MODE:SYNC_DIRECT}

    # Example plan. Keep disabled until the tachograph datasource/extractor is wired.
    import-plans:
      - plan-key: tachograph-org-14708
        enabled: false
        cron: "" #"0 15 * * * *" # hourly at minute 15
        tenant-key: Procon
        event-source:
          provider-key: TACHOGRAPH
          source-kind: MIXED
          source-key: TACHOGRAPH_DB
          source-instance-key: ByteBar-DriverSettlement
          tenant-provider-setting-key: ByteBar-DriverSettlement
        source-group:
          type: ORGANISATION
          source-entity-id: "14708"
          code: "14708"
          name: Zeller root organisation
        import-scope:
          type: SOURCE_ORGANISATION_SUBTREE
          root-source-organisation:
            type: ORGANISATION
            source-entity-id: "14708"
            code: "14708"
            name: Zeller root organisation
          include-children: true
          occurred-from: null
          occurred-to: null
        event-families:
          - DRIVER_ACTIVITY
          - DRIVER_CARD
          - POSITION
          - BORDER_CROSSING
          - LOAD_UNLOAD
          - PLACE
          - SPECIFIC_CONDITION
          - SPEEDING
        initial-mode: INITIAL_BACKFILL
        scheduled-mode: INITIAL_BACKFILL # INITIAL_BACKFILL INCREMENTAL_UPDATE
        initial-strategy: OCCURRED_AT_WINDOW_WITH_OVERLAP
        scheduled-strategy: SOURCE_PACKAGE_WATERMARK
        refresh-master-data-first: true
        initial-occurred-from: "2026-04-01T00:00:00+01:00"
        initial-occurred-to: "2026-04-10T00:00:00+01:00"
        run-initial-on-startup: true

  tachograph-file-session:
    ttl: 4h
    max-sessions: 100
    max-file-size-bytes: 20971520
    processing:
      operating-split-idle-hours: 7
      significant-driving-minutes: 3
      merge-gap-seconds: 0
      gap-detection-tolerance-seconds: 0
      timeline-input-mode: events
    legal-requirements:
      base-url: ${LEGAL_REQUIREMENTS_BASE_URL:https://legalrequirements.services.bytebar.eu/ODataV4/LR}
      username: ${LEGAL_REQUIREMENTS_USERNAME:}
      password: ${LEGAL_REQUIREMENTS_PASSWORD:}
      connect-timeout: 20s
      read-timeout: 2m
      reset-session-after-use: false

  esper-poc:
    activity-merge-mode: JAVA
    shift-resolution-mode: JAVA
    operating-period-evaluation:
      operating-split-idle-hours: 7
      significant-driving-minutes: 3
      merge-gap-seconds: 0
      gap-detection-tolerance-seconds: 0
      unknown-treatment-mode: AS_BREAK_REST
      engine-mode: STREAM_COLLECTOR

  yellow-fox:
    default-chunk-days: 1
    occurred-at-overlap: 2h
    emit-initial-ignition-snapshot: false
    sync-vehicle-registrations-on-master-data-update: false

    # JDBC extraction handoff mode:
    # SYNC_DIRECT = persist controlled JDBC batches directly, cursor-safe default.
    # CAMEL_ROUTE = persist the same controlled batches through direct:eventhub-batch-persist-input.
    jdbc-extraction-ingest-mode: ${YELLOWFOX_JDBC_EXTRACTION_INGEST_MODE:SYNC_DIRECT}

    datasource:
      jdbc-url: ${YELLOWFOX_DB_JDBC_URL:}
      username: ${YELLOWFOX_DB_USERNAME:}
      password: ${YELLOWFOX_DB_PASSWORD:}
      driver-class-name: org.postgresql.Driver

    scheduler-enabled: false
    scheduler-poll-interval-ms: 60000
    scheduler-trigger-mode: EXECUTE

    import-plans:
      - plan-key: yellowfox-d8-default
        enabled: false
        cron: "" #"0 */5 * * * *"
        tenant-key: Procon
        event-source:
          provider-key: YELLOWFOX
          source-kind: TELEMATICS_PLATFORM
          source-key: YELLOWFOX_D8
          source-instance-key: logistics-db-prod
          tenant-provider-setting-key: yellowfox-main
        source-group:
          type: FLEET
          source-entity-id: "7"
        import-scope:
          type: TENANT_ALL
          include-children: false
        event-families:
          - DRIVER_ACTIVITY
          - DRIVER_CARD
        initial-mode: INITIAL_BACKFILL
        scheduled-mode: INITIAL_BACKFILL # INITIAL_BACKFILL, INCREMENTAL_UPDATE
        initial-strategy: OCCURRED_AT_WINDOW_WITH_OVERLAP
        scheduled-strategy: SOURCE_ROW_WATERMARK
        initial-occurred-from: "2026-04-01T00:00:00+01:00"
        initial-occurred-to: "2026-04-10T00:00:00+01:00"
        refresh-master-data-first: true
        run-initial-on-startup: true
