/**
 * Extraction Service — Fastify server entry point.
 *
 * Modules: extract, tasks.
 * Port: 4005 (configurable via PORT env var).
 * Product-agnostic: all data scoped by productId.
 *
 * Depends on a Python sidecar running LangExtract (default port 4006).
 */

// Resolve secrets from configured provider BEFORE config parsing
import { resolveSecrets, LYSNR_SECRETS } from '@bytelyst/config';
await resolveSecrets([
  LYSNR_SECRETS.COSMOS_KEY,
  LYSNR_SECRETS.COSMOS_ENDPOINT,
  LYSNR_SECRETS.JWT_SECRET,
  LYSNR_SECRETS.GEMINI_API_KEY,
]);

import { createServiceApp, startService } from '@bytelyst/fastify-core';
import { extractRoutes } from './modules/extract/routes.js';
import { taskRoutes } from './modules/tasks/routes.js';
import { transcribeRoutes } from './modules/transcribe/routes.js';
import { config } from './lib/config.js';

const app = await createServiceApp({
  name: 'extraction-service',
  version: '0.1.0',
  description: 'LLM-powered structured extraction via LangExtract — product-agnostic',
  corsOrigin: config.CORS_ORIGIN,
  swagger: {
    title: 'Extraction Service',
    description: 'LLM-powered structured extraction via LangExtract',
    port: config.PORT,
  },
  metrics: true,
});

// Register route modules
await app.register(extractRoutes, { prefix: '/api' });
await app.register(taskRoutes, { prefix: '/api' });
await app.register(transcribeRoutes, { prefix: '/api' });

await startService(app, { port: config.PORT, host: config.HOST });
