import { Global, Module } from '@nestjs/common';
import { createBrain, type Brain } from '@mosaicstack/brain';
import type { Db } from '@mosaicstack/db';
import { DB } from '../database/database.module.js';
import { BRAIN } from './brain.tokens.js';

@Global()
@Module({
  providers: [
    {
      provide: BRAIN,
      useFactory: (db: Db): Brain => createBrain(db),
      inject: [DB],
    },
  ],
  exports: [BRAIN],
})
export class BrainModule {}
