import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtService } from '@nestjs/jwt';
import { VcmCommissionDifferenceReasonEntity } from 'src/entities/VcmCommissionDifferenceReason.entity';
import { CommissionDifferenceReasonService } from './commission-difference-reason.service';
import { CommissionDifferenceReasonController } from './commission-difference-reason.controller';
import { CacheModule } from '@nestjs/cache-manager';
import { RedisService } from 'src/modules/backend/redis/redis.service';

/**
 * Commission Difference Reason Module
 *
 * This module encapsulates all functionality related to managing commission difference reasons.
 * Commission difference reasons are used to categorize and explain discrepancies or variances
 * in commission calculations within the visa commission management system.
 *
 * The module follows NestJS modular architecture, grouping together:
 * - Controllers (API endpoints)
 * - Services (Business logic)
 * - Entities (Database models)
 * - Dependencies (JWT, Cache, Redis)
 *
 * @Module - Decorator that defines this as a NestJS module
 *
 * @example
 * // Import in AppModule or parent module:
 * imports: [CommissionDifferenceReasonModule, ...]
 */
@Module({
  /**
   * Controllers that handle HTTP requests for this module.
   * CommissionDifferenceReasonController defines all CRUD and search endpoints
   * for managing commission difference reasons.
   */
  controllers: [CommissionDifferenceReasonController],

  /**
   * Providers (services, utilities) for this module.
   *
   * 1. CommissionDifferenceReasonService - Main business logic service
   * 2. JwtService - JSON Web Token service for authentication (likely used in guards)
   * 3. RedisService - Redis client service for caching or session management
   *
   * @note JwtService is likely used by SessionGuard but might be better provided
   * at the global AppModule level if used across multiple modules.
   */
  providers: [
    CommissionDifferenceReasonService, // Main business logic
    JwtService, // Authentication token handling
    RedisService, // Redis caching/session management
  ],

  /**
   * Modules and entities that this module depends on.
   *
   * 1. CacheModule - For in-memory caching (could be configured to use Redis)
   * 2. TypeOrmModule.forFeature() - Registers entities for dependency injection
   *
   * @note Consider whether CacheModule should use Redis store if RedisService
   * is already imported. Currently might be using separate cache stores.
   */
  imports: [
    // Cache module for temporary data storage
    // By default uses memory store, but can be configured for Redis
    CacheModule.register(),

    // Register the entity with TypeORM for this module
    // Makes VcmCommissionDifferenceReasonEntity available for injection in services
    TypeOrmModule.forFeature([VcmCommissionDifferenceReasonEntity]),
  ],

  /**
   * Optional: Export providers to make them available to other modules.
   * Currently not exporting anything, which keeps this module self-contained.
   *
   * Consider exporting if:
   * 1. Other modules need to use CommissionDifferenceReasonService
   * 2. The entity needs to be used in other modules' repositories
   */
  exports: [
    // Currently not exporting anything
    // Could export: CommissionDifferenceReasonService, TypeOrmModule
  ],
})
export class CommissionDifferenceReasonModule {}
