import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { JwtStrategy } from './infrastructure/strategies/jwt.strategy';

// Domain entities
import { User } from './domain/entities/user.entity';
import { KycSubmission } from './domain/entities/kyc-submission.entity';
import { Wallet } from './domain/entities/wallet.entity';
import { Transaction } from './domain/entities/transaction.entity';
import { Message } from './domain/entities/message.entity';

// Domain repository interfaces
import { USER_REPOSITORY } from './domain/repositories/user.repository.interface';
import { KYC_REPOSITORY } from './domain/repositories/kyc.repository.interface';
import { WALLET_REPOSITORY } from './domain/repositories/wallet.repository.interface';
import { TRANSACTION_REPOSITORY } from './domain/repositories/transaction.repository.interface';
import { MESSAGE_REPOSITORY } from './domain/repositories/message.repository.interface';

// Infrastructure implementations
import { UserRepository } from './infrastructure/persistence/user.repository';
import { KycRepository } from './infrastructure/persistence/kyc.repository';
import { WalletRepository } from './infrastructure/persistence/wallet.repository';
import { TransactionRepository } from './infrastructure/persistence/transaction.repository';
import { MessageRepository } from './infrastructure/persistence/message.repository';

// Application services
import { UserProfileService } from './application/services/user-profile.service';
import { KycService } from './application/services/kyc.service';
import { WalletService } from './application/services/wallet.service';
import { MessageService } from './application/services/message.service';
import { AdminDashboardService } from './application/services/admin-dashboard.service';
import { AdminUserService } from './application/services/admin-user.service';
import { AdminSystemService } from './application/services/admin-system.service';
import { AdminAnalyticsService } from './application/services/admin-analytics.service';

// Interface controllers
import { UserController } from './interface/http/controllers/user.controller';
import { KycController } from './interface/http/controllers/kyc.controller';
import { WalletController } from './interface/http/controllers/wallet.controller';
import { MessageController } from './interface/http/controllers/message.controller';
import { AdminDashboardController } from './interface/http/controllers/admin-dashboard.controller';
import { AdminUserController } from './interface/http/controllers/admin-user.controller';
import { AdminSystemController } from './interface/http/controllers/admin-system.controller';
import { AdminAnalyticsController } from './interface/http/controllers/admin-analytics.controller';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      User, KycSubmission, Wallet, Transaction, Message,
    ]),
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.register({
      secret: process.env.JWT_ACCESS_SECRET || 'dev-access-secret',
    }),
  ],
  controllers: [
    UserController, KycController, WalletController, MessageController,
    AdminDashboardController, AdminUserController, AdminSystemController, AdminAnalyticsController,
  ],
  providers: [
    JwtStrategy,
    // Infrastructure -> Domain port binding
    { provide: USER_REPOSITORY, useClass: UserRepository },
    { provide: KYC_REPOSITORY, useClass: KycRepository },
    { provide: WALLET_REPOSITORY, useClass: WalletRepository },
    { provide: TRANSACTION_REPOSITORY, useClass: TransactionRepository },
    { provide: MESSAGE_REPOSITORY, useClass: MessageRepository },

    // Application services
    UserProfileService, KycService, WalletService, MessageService,
    AdminDashboardService, AdminUserService, AdminSystemService, AdminAnalyticsService,
  ],
  exports: [UserProfileService, WalletService, MessageService],
})
export class UserModule {}
