// ============================================================
// Plugin: secretaria — Secretária IA Multi-Nó
// ============================================================
import type { PluginInstance, PluginContext } from '../../backend/src/core/types'
import { runMigrations } from './migrate'
import { createSecretariaRoutes } from './routes'
import manifest from './manifest.json'

const plugin: PluginInstance = {
  manifest: manifest as any,

  async activate(ctx: PluginContext): Promise<void> {
    // 1. Cria tabelas e seed inicial
    await runMigrations(ctx.db)
    ctx.logger.info('[secretaria] Tabelas criadas/verificadas')

    // 2. Registra rotas REST
    const router = createSecretariaRoutes(ctx.db, ctx.config)
    ctx.app.use('/api/secretaria', router)
    ctx.logger.info('[secretaria] Rotas registradas em /api/secretaria')
  },

  async deactivate(ctx: PluginContext): Promise<void> {
    ctx.logger.info('[secretaria] Desativado')
  },
}

export default plugin
