import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PortsController } from '../controllers/ports.controller';

// Import domain services
import { PortSearchService } from '@domain/services/port-search.service';

// Import domain ports
import { PORT_REPOSITORY } from '@domain/ports/out/port.repository';

// Import infrastructure implementations
import { TypeOrmPortRepository } from '../../infrastructure/persistence/typeorm/repositories/typeorm-port.repository';
import { PortOrmEntity } from '../../infrastructure/persistence/typeorm/entities/port.orm-entity';

@Module({
  imports: [TypeOrmModule.forFeature([PortOrmEntity])],
  controllers: [PortsController],
  providers: [
    {
      provide: PORT_REPOSITORY,
      useClass: TypeOrmPortRepository,
    },
    {
      provide: PortSearchService,
      useFactory: (portRepo: any) => {
        return new PortSearchService(portRepo);
      },
      inject: [PORT_REPOSITORY],
    },
  ],
  exports: [PORT_REPOSITORY, PortSearchService],
})
export class PortsModule {}
