// Import core NestJS module decorator
import { Module } from '@nestjs/common';

// Import controller
import { MenusController } from './menus.controller';

// Import TypeORM integration for database operations
import { TypeOrmModule } from '@nestjs/typeorm';

// Import JWT service for token handling
import { JwtService } from '@nestjs/jwt';

// Import service containing business logic
import { MenusService } from './menus.service';

// Import entities representing database tables
import { MenusEntity } from 'src/entities/Menus.entity';

// Import cache module for caching capabilities
import { CacheModule } from '@nestjs/cache-manager';

// Import custom Redis service for advanced cache management
import { RedisService } from '../redis/redis.service';

// Import related entity for menu actions
import { MenuActionsEntity } from 'src/entities/MenuActions.entity';

/**
 * MenusModule - Feature module for menus management functionality
 *
 * This module encapsulates all components related to menus including:
 * - Menu items themselves
 * - Associated menu actions (permissions/operations)
 * - Caching layer for performance
 * - Authentication integration
 *
 * The module follows NestJS modular architecture where related features
 * are grouped together for better organization, dependency management,
 * and lazy loading capabilities.
 */
@Module({
  /**
   * controllers - Array of controllers that handle HTTP requests
   *
   * MenusController: Defines REST endpoints for menu operations including:
   * - CRUD operations for menus
   * - Search with filtering and pagination
   * - Menu status management
   * - User activity tracking
   */
  controllers: [MenusController],

  /**
   * providers - Injectable services and classes available within this module
   *
   * 1. MenusService: Core business logic service for menu operations
   *    - Contains menu CRUD, search, and business validation logic
   *    - Handles relationships with menu groups and actions
   *
   * 2. JwtService: Utility for JWT token operations
   *    - Likely used by RedisService for token validation
   *    - May be used by SessionGuard for authentication
   *    - Provided here for dependency injection to other services
   *
   * 3. RedisService: Custom Redis implementation
   *    - Manages distributed caching for menu data
   *    - May cache frequently accessed menus or permission data
   *    - Could implement cache invalidation strategies for menu updates
   */
  providers: [MenusService, JwtService, RedisService],

  /**
   * imports - External modules and dependencies required by this module
   *
   * 1. CacheModule.register(): Configures the caching system
   *    - Provides default in-memory caching
   *    - Enables use of @CacheKey(), @CacheTTL() decorators
   *    - Note: RedisService may override or extend this functionality
   *
   * 2. TypeOrmModule.forFeature([MenusEntity, MenuActionsEntity]):
   *    - Registers both entities with TypeORM
   *    - Makes MenusRepository and MenuActionsRepository injectable
   *    - Enables database operations for both tables
   *    - Supports the relationship between menus and their actions
   */
  imports: [
    CacheModule.register(), // Default cache configuration
    TypeOrmModule.forFeature([MenusEntity, MenuActionsEntity]), // Database entities
  ],
})
export class MenusModule {}
