{{{
  exports({ to: app.configPath('jobs.ts') })
}}}
import type { InferQueues } from '@eienjs/adonisjs-jobs/types'
import env from '#start/env'
import { defineConfig } from '@eienjs/adonisjs-jobs'

const jobsConfig = defineConfig({
  // Database Connection (reuse same DB connection as Lucid)
  host: env.get('DB_HOST'),
  port: env.get('DB_PORT'),
  user: env.get('DB_USER'),
  password: env.get('DB_PASSWORD'),
  database: env.get('DB_DATABASE'),

  // pg-boss schema (separate from your app tables)
  schema: 'pgboss',

  // Auto-discovery settings
  jobsPath: 'app/jobs',                       // Path to scan for dispatchable job classes (*_job.ts)
  cronPath: 'app/cron',                       // Path to scan for schedulable cron classes (*_cron.ts)

  queues: ['default', 'emails', 'reports'] as const,  // Available queues
  defaultQueue: 'default',                   // Default queue for jobs without static queue

  // Job Lifecycle Management - Full Audit History
  retentionDays: 7,                           // Keep completed jobs for 7 days
  archiveCompletedAfterSeconds: 43200,        // Archive after 12 hours
  deleteAfterDays: 36500,                     // Keep archived jobs for ~100 years (effectively permanent)

  // Performance Tuning
  pollingIntervalSeconds: 2,                  // How often to poll for jobs
  maintenanceIntervalSeconds: 120,            // Background maintenance interval

  // Default Job Settings (can be overridden per-job)
  retryLimit: 3,                              // Default retry attempts
  retryDelay: 30,                             // Default retry delay (seconds)
  retryBackoff: true,                         // Enable exponential backoff
  expireInHours: 23,                          // Default job expiration

  // Graceful shutdown timeout
  shutdownTimeoutMs: 10000,                  // 10 seconds timeout for graceful shutdown
})

export type QueueNames = InferQueues<typeof jobsConfig>;

export default jobsConfig
