import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserModule } from './user/user.module';
import { WorkspaceModule } from './workspace/workspace.module';
import { ProjectModule } from './project/project.module';
import { AuthModule } from './auth/auth.module';
import { AiModule } from './ai/ai.module';
import { User } from './user/user.entity';
import { Workspace } from './workspace/workspace.entity';
import { Project } from './project/project.entity';
import { AiConfig } from './ai/ai-config.entity';
import { PluginConfig } from './plugins/plugin-config.entity';
import { AppController } from './app.controller';
import { AppService } from './app.service';

// 数据库实体
const ENTITIES = [User, Workspace, Project, AiConfig, PluginConfig];

// 数据库配置
const DATABASE_CONFIG = TypeOrmModule.forRoot({
  type: 'postgres',
  host: 'localhost',
  port: 5432,
  username: 'postgres',
  password: 'postgres',
  database: 'aiframe',
  entities: ENTITIES,
  synchronize: true,
});

// 功能模块
const MODULES = [
  DATABASE_CONFIG,
  AuthModule,
  UserModule,
  WorkspaceModule,
  ProjectModule,
  AiModule,
];

@Module({
  imports: MODULES,
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}