import { Module } from '@nestjs/common';
import { CommissionResponseReasonController } from './commission-response-reason.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtService } from '@nestjs/jwt';
import { CommissionResponseReasonService } from './commission-response-reason.service';
import { VcmCommissionResponseReasonEntity } from 'src/entities/VcmCommissionResponseReason.entity';
import { CacheModule } from '@nestjs/cache-manager';
import { RedisService } from 'src/modules/backend/redis/redis.service';

/**
 * Commission Response Reason Module
 *
 * This module encapsulates all functionality related to managing commission response reasons.
 * Commission response reasons are used to categorize and document responses or explanations
 * provided for commission calculations or queries within the visa commission management system.
 *
 * The module follows the same pattern as CommissionDifferenceReasonModule, suggesting
 * potential code duplication that could be refactored into a shared module.
 *
 * @Module - Decorator that defines this as a NestJS module
 *
 * @example
 * // Import in AppModule or parent module:
 * imports: [CommissionResponseReasonModule, ...]
 *
 * @note This module structure is nearly identical to CommissionDifferenceReasonModule.
 * Consider creating a generic master data module or using dynamic module creation.
 */
@Module({
  /**
   * Controller that handles HTTP requests for commission response reasons.
   * CommissionResponseReasonController provides CRUD and search endpoints.
   */
  controllers: [CommissionResponseReasonController],

  /**
   * Providers (services, utilities) for this module.
   *
   * 1. CommissionResponseReasonService - Main business logic service
   * 2. JwtService - JSON Web Token service for authentication
   * 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: [
    CommissionResponseReasonService, // 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
   * 2. TypeOrmModule.forFeature() - Registers entity for dependency injection
   *
   * @note Consider whether CacheModule should be configured differently
   * if RedisService is also being used.
   */
  imports: [
    // Cache module for temporary data storage
    // Default memory store, separate from RedisService
    CacheModule.register(),

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

  /**
   * Optional: Export providers to make them available to other modules.
   * Currently not exporting anything, which keeps this module self-contained.
   */
  exports: [
    // Could export if other modules need access to the service or entity
    // CommissionResponseReasonService,
    // TypeOrmModule,
  ],
})
export class CommissionResponseReasonModule {}
