import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AI3DController } from './ai-3d.controller';
import { AI3DService } from './ai-3d.service';
import { MockAI3DProvider } from './providers/mock.provider';
import { HunyuanAI3DProvider } from './providers/hunyuan.provider';
import { AI3D_PROVIDER } from './providers/ai-3d-provider.interface';
import { PrismaModule } from '../prisma/prisma.module';

@Module({
  imports: [PrismaModule, ConfigModule],
  controllers: [AI3DController],
  providers: [
    AI3DService,
    MockAI3DProvider,
    HunyuanAI3DProvider,
    {
      provide: AI3D_PROVIDER,
      useFactory: (
        configService: ConfigService,
        mockProvider: MockAI3DProvider,
        hunyuanProvider: HunyuanAI3DProvider,
      ) => {
        const provider = configService.get<string>('AI_3D_PROVIDER') || 'mock';

        switch (provider.toLowerCase()) {
          case 'hunyuan':
            return hunyuanProvider;
          case 'mock':
          default:
            return mockProvider;
        }
      },
      inject: [ConfigService, MockAI3DProvider, HunyuanAI3DProvider],
    },
  ],
  exports: [AI3DService],
})
export class AI3DModule {}
