import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { DatabaseModule } from '@it0/database';

// Domain Entities
import { ReferralCode } from './domain/entities/referral-code.entity';
import { ReferralRelationship } from './domain/entities/referral-relationship.entity';
import { ReferralReward } from './domain/entities/referral-reward.entity';
import { ReferralStat } from './domain/entities/referral-stat.entity';
import { ProcessedEvent } from './domain/entities/processed-event.entity';

// Infrastructure Repositories
import { ReferralCodeRepository } from './infrastructure/repositories/referral-code.repository';
import { ReferralRelationshipRepository } from './infrastructure/repositories/referral-relationship.repository';
import { ReferralRewardRepository } from './infrastructure/repositories/referral-reward.repository';
import { ReferralStatRepository } from './infrastructure/repositories/referral-stat.repository';
import { ProcessedEventRepository } from './infrastructure/repositories/processed-event.repository';
// User-level repositories
import { UserReferralCodeRepository } from './infrastructure/repositories/user-referral-code.repository';
import { UserReferralRelationshipRepository } from './infrastructure/repositories/user-referral-relationship.repository';
import { UserPointRepository } from './infrastructure/repositories/user-point.repository';

// Application Use Cases
import { GetMyReferralInfoUseCase } from './application/use-cases/get-my-referral-info.use-case';
import { ValidateReferralCodeUseCase } from './application/use-cases/validate-referral-code.use-case';
import { RegisterWithCodeUseCase } from './application/use-cases/register-with-code.use-case';
import { ConsumePaymentReceivedUseCase } from './application/use-cases/consume-payment-received.use-case';
import { GetReferralListUseCase } from './application/use-cases/get-referral-list.use-case';
import { GetPendingCreditsUseCase } from './application/use-cases/get-pending-credits.use-case';
// User-level use cases
import { RegisterUserReferralUseCase } from './application/use-cases/register-user-referral.use-case';
import { ConsumeUserPaymentUseCase } from './application/use-cases/consume-user-payment.use-case';
import { GetMyUserReferralInfoUseCase } from './application/use-cases/get-my-user-referral-info.use-case';
import { GetMyCircleUseCase } from './application/use-cases/get-my-circle.use-case';

// Controllers
import { ReferralController } from './interfaces/rest/controllers/referral.controller';
import { ReferralInternalController } from './interfaces/rest/controllers/referral-internal.controller';
import { ReferralAdminController } from './interfaces/rest/controllers/referral-admin.controller';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    DatabaseModule.forRoot(),
    TypeOrmModule.forFeature([
      ReferralCode,
      ReferralRelationship,
      ReferralReward,
      ReferralStat,
      ProcessedEvent,
    ]),
  ],
  controllers: [
    ReferralController,
    ReferralInternalController,
    ReferralAdminController,
  ],
  providers: [
    // Tenant-level repositories (B2B)
    ReferralCodeRepository,
    ReferralRelationshipRepository,
    ReferralRewardRepository,
    ReferralStatRepository,
    ProcessedEventRepository,
    // User-level repositories (C2C personal circle + points)
    UserReferralCodeRepository,
    UserReferralRelationshipRepository,
    UserPointRepository,

    // Tenant-level use cases
    GetMyReferralInfoUseCase,
    ValidateReferralCodeUseCase,
    RegisterWithCodeUseCase,
    ConsumePaymentReceivedUseCase,
    GetReferralListUseCase,
    GetPendingCreditsUseCase,
    // User-level use cases
    RegisterUserReferralUseCase,
    ConsumeUserPaymentUseCase,
    GetMyUserReferralInfoUseCase,
    GetMyCircleUseCase,
  ],
})
export class ReferralModule {}
