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

// Import controller
import { UserSettingsController } from './user-settings.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 { UserSettingsService } from './user-settings.service';

// Import entity definitions
import { UserSettingsEntity } from 'src/entities/UserSettings.entity';

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

// Import additional entity for table settings
import { LmsTableSettingsEntity } from 'src/entities/LmsTableSettings.entity';

// Import shared table settings service
import { TableSettingsService } from 'src/services/table-settings.service';

/**
 * UserSettingsModule - Feature module for user settings management
 *
 * This module encapsulates components for managing user-specific settings
 * and preferences, with a focus on table/view customization. It demonstrates
 * service reuse and clean separation between general settings and table settings.
 *
 * Business Domain: User Configuration Management
 * - Manages user-specific application settings
 * - Handles table/view customization preferences
 * - Supports user personalization across the application
 *
 * Module Characteristics:
 * - Lightweight module with focused responsibility
 * - Integration with shared TableSettingsService
 * - Caching for performance optimization
 * - JWT support for authentication
 *
 * Key Design: Service Reuse Pattern
 * - TableSettingsService is a shared service used across multiple modules
 * - Promotes DRY (Don't Repeat Yourself) principles
 * - Ensures consistent table settings behavior application-wide
 */
@Module({
  /**
   * controllers - Array of controllers that handle HTTP requests
   *
   * UserSettingsController: Provides endpoints for user settings management
   * - CRUD operations for general user settings
   * - Specialized endpoint for table settings via shared service
   * - RESTful design with proper HTTP methods
   */
  controllers: [UserSettingsController],

  /**
   * providers - Injectable services available within this module
   *
   * 1. UserSettingsService: Core business logic for user settings
   *    - Handles CRUD operations for user settings
   *    - Manages user preference persistence
   *    - Integrates with UserSettingsEntity repository
   *
   * 2. JwtService: Utility for JWT token operations
   *    - Supports authentication mechanisms
   *    - Likely used by guards/strategies in parent modules
   *    - Enables token-based authentication for protected endpoints
   *
   * 3. TableSettingsService: Shared service for table settings
   *    - Reusable service for table/view customization
   *    - Implements 'autoGetPageSettings' intelligent logic
   *    - Used across multiple modules for consistent table settings
   *    - Promotes code reuse and maintainability
   */
  providers: [UserSettingsService, JwtService, TableSettingsService],

  /**
   * imports - External modules and dependencies required by this module
   *
   * 1. CacheModule.register(): Configures the caching system
   *    - Provides in-memory caching by default
   *    - Important for frequently accessed user settings
   *    - Reduces database load for preference queries
   *
   * 2. TypeOrmModule.forFeature([...]): Registers entities with TypeORM
   *    - Creates repositories for database operations
   *    - Enables dependency injection of repositories
   */
  imports: [
    CacheModule.register(), // Default cache configuration

    /**
     * TypeOrmModule.forFeature with 2 entities:
     * This represents the data model for user settings management
     */
    TypeOrmModule.forFeature([
      /**
       * 1. UserSettingsEntity - General user settings
       *    - Stores user-specific application preferences
       *    - May include: theme preferences, layout settings, notification preferences
       *    - General configuration beyond table-specific settings
       *    - One-to-one or one-to-many relationship with users
       */
      UserSettingsEntity,

      /**
       * 2. LmsTableSettingsEntity - Table/view customization
       *    - Stores user-specific table configurations
       *    - Column visibility, order, sorting, filtering preferences
       *    - Pagination settings and view customizations
       *    - Used by TableSettingsService for intelligent defaults
       */
      LmsTableSettingsEntity,
    ]),
  ],
})
export class UserSettingsModule {}
