/**
 * Worker do Temporal — roda como processo separado.
 * Uso: npx tsx src/infra/temporal/temporalWorker.ts
 */
import { Worker } from '@temporalio/worker'
import { env } from '../../config/env'
import { logger } from '../../config/logger'
import * as activities from './activities'

async function runWorker() {
  const worker = await Worker.create({
    workflowsPath: require.resolve('./workflows'),
    activities,
    taskQueue: env.TEMPORAL_TASK_QUEUE,
    namespace: env.TEMPORAL_NAMESPACE,
  })

  logger.info({ taskQueue: env.TEMPORAL_TASK_QUEUE }, '🕰  Temporal Worker iniciado')
  await worker.run()
}

runWorker().catch((err) => {
  logger.error(err, 'Falha fatal no Temporal Worker')
  process.exit(1)
})
