import type { FastifyInstance } from 'fastify';
import { db } from '../db/client.js';

export async function registerSchemaRoutes(app: FastifyInstance) {
  app.get('/api/schema/tables', async () => {
    const tables = await db('information_schema.tables')
      .select('table_name', 'table_schema')
      .where('table_type', 'BASE TABLE')
      .whereNotIn('table_schema', ['pg_catalog', 'information_schema'])
      .orderBy('table_schema')
      .orderBy('table_name');

    return {
      items: tables,
    };
  });
}
