# Demo: diverse export shapes exercising every recommendation reason and
# several source-group collision scenarios.
#
#   source_group: replica_primary    — 3 exports share this (shared-source warning)
#   source_group: replica_analytics  — 2 medium-cost exports
#
#   Strategies:
#     full           : users, product_catalog, email_queue, orders_sparse
#     incremental    : events (strong cursor), transactions (strong), sessions
#     coalesce       : logs_archive, orders_coalesce (composite cursor, ADR-0007)
#     chunked        : audit_log, page_views, metric_samples (heavy, checkpoint)
#
source:
  type: postgres
  url_env: DATABASE_URL
  tuning:
    profile: balanced

exports:
  # --- source_group: replica_primary (3+ → warning) ---
  - name: transactions
    source_group: replica_primary
    query: "SELECT id, user_id, amount, status, created_at, updated_at FROM transactions"
    mode: incremental
    cursor_column: updated_at
    format: parquet
    destination:
      type: local
      path: ./out

  - name: audit_log
    source_group: replica_primary
    query: "SELECT id, actor_id, action_hash, action, logged_at FROM audit_log"
    mode: chunked
    chunk_column: id
    chunk_size: 200000
    chunk_checkpoint: true
    chunk_max_attempts: 3
    parallel: 2
    reconcile_required: true         # advisory hint (Epic C)
    format: parquet
    destination:
      type: local
      path: ./out

  - name: sessions
    source_group: replica_primary
    query: "SELECT id, session_uuid::text, user_id, session_start, session_end FROM sessions"
    mode: incremental
    cursor_column: session_start
    format: parquet
    destination:
      type: local
      path: ./out

  # --- source_group: replica_analytics ---
  - name: metric_samples
    source_group: replica_analytics
    query: "SELECT id, host, metric_name, value, captured_at FROM metric_samples"
    mode: chunked
    chunk_column: id
    chunk_size: 100000
    chunk_checkpoint: true
    format: parquet
    destination:
      type: local
      path: ./out

  - name: logs_archive
    source_group: replica_analytics
    query: "SELECT id, payload, created_at, updated_at FROM logs_archive"
    mode: incremental
    cursor_column: updated_at
    cursor_fallback_column: created_at
    incremental_cursor_mode: coalesce
    format: parquet
    destination:
      type: local
      path: ./out

  # --- ungrouped ---
  - name: events
    query: "SELECT id, user_id, event_type, payload::text AS payload, ip_address, created_at FROM events"
    mode: incremental
    cursor_column: created_at
    format: parquet
    destination:
      type: local
      path: ./out

  - name: orders_coalesce
    query: "SELECT id, product, quantity, price, updated_at, created_at FROM orders_coalesce"
    mode: incremental
    cursor_column: updated_at
    cursor_fallback_column: created_at
    incremental_cursor_mode: coalesce
    format: parquet
    destination:
      type: local
      path: ./out

  - name: page_views
    query: "SELECT id, session_id, user_id, url, country_code, device_type, browser, created_at FROM page_views"
    mode: chunked
    chunk_column: id
    chunk_size: 100000
    chunk_checkpoint: true
    format: parquet
    destination:
      type: local
      path: ./out

  - name: product_catalog
    query: "SELECT sku, name, category, price, active, updated_at FROM product_catalog"
    mode: full
    format: parquet
    destination:
      type: local
      path: ./out

  - name: users
    query: "SELECT id, name, email, age, balance, is_active, created_at, updated_at FROM users"
    mode: full
    format: parquet
    destination:
      type: local
      path: ./out

  - name: email_queue
    query: "SELECT id, to_email, subject, status, scheduled_at FROM email_queue"
    mode: full
    format: parquet
    destination:
      type: local
      path: ./out

  - name: orders_sparse
    query: "SELECT id, payload FROM orders_sparse"
    mode: full
    format: parquet
    destination:
      type: local
      path: ./out
