import { Module } from '@nestjs/common';
import { CoursePortalController } from './course-portal.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtService } from '@nestjs/jwt';
import { CoursePortalService } from './course-portal.service';
import { CacheModule } from '@nestjs/cache-manager';
import { CourseMasterEntity } from 'src/entities/CourseMaster.entity';
import { CoursesTransformer } from './transformers/courses.transform';
import { CourseMasterIntakeYearsEntity } from 'src/entities/CourseMasterIntakeYears.entity';
import { StudyLevelMasterEntity } from 'src/entities/StudyLevelMaster.entity';
import { StreamMasterEntity } from 'src/entities/StreamMaster.entity';
import { LanguageProficiencyScoringEntity } from 'src/entities/LanguageProficiencyScoring.entity';
import { AcademyProficiencyScoringEntity } from 'src/entities/AcademyProficiencyScoring.entity';
import { OptionsTransformer } from './transformers/options.transform';
import { StateEntity } from 'src/entities/State.entity';
import { CityEntity } from 'src/entities/City.entity';
import { SubstreamMasterEntity } from 'src/entities/SubstreamMaster.entity';

/**
 * Course Portal Module
 *
 * This module encapsulates all components related to the course portal feature:
 * - Controllers: Handle HTTP requests
 * - Services: Contain business logic
 * - Transformers: Convert data between formats
 * - Entities: Database models
 *
 * The module follows the NestJS modular architecture pattern, grouping related
 * functionality together for better organization, testability, and reusability.
 *
 * @Module - Decorator that marks this class as a NestJS module
 *
 * @example
 * // Import this module in the root AppModule
 * imports: [CoursePortalModule, ...]
 */
@Module({
  /**
   * Controllers that handle incoming HTTP requests for this module.
   * CoursePortalController defines all course portal API endpoints.
   */
  controllers: [CoursePortalController],

  /**
   * Providers (services, helpers, transformers) that can be injected
   * throughout this module and other modules that import this module.
   */
  providers: [
    CoursePortalService, // Main business logic service
    JwtService, // JSON Web Token service for authentication
    CoursesTransformer, // Transforms raw course data to DTO format
    OptionsTransformer, // Transforms data to standardized option format
  ],

  /**
   * Imported modules and TypeORM entities that this module depends on.
   * TypeOrmModule.forFeature() makes entities available for injection
   * in services within this module.
   */
  imports: [
    // Cache module for application-level caching
    CacheModule.register(),

    // Register TypeORM entities for this module
    TypeOrmModule.forFeature([
      // Course-related entities
      CourseMasterIntakeYearsEntity, // Course intake years/semesters
      CourseMasterEntity, // Main course information

      // Categorization entities
      StudyLevelMasterEntity, // Study levels (Undergraduate, Postgraduate, etc.)
      StreamMasterEntity, // Academic streams (Engineering, Business, etc.)
      SubstreamMasterEntity, // Specializations within streams

      // Scoring/assessment entities
      LanguageProficiencyScoringEntity, // Language proficiency requirements
      AcademyProficiencyScoringEntity, // Academic proficiency requirements

      // Location entities
      StateEntity, // States/provinces
      CityEntity, // Cities
    ]),
  ],

  /**
   * Optional: Export providers to make them available to other modules.
   * If other modules need to use CoursePortalService, they can import
   * CoursePortalModule and get access to exported providers.
   */
  exports: [
    CoursePortalService, // Optional: Export if service needs to be used elsewhere
    // CoursesTransformer, // Usually not exported unless specifically needed
    // OptionsTransformer, // Usually not exported unless specifically needed
  ],
})
export class CoursePortalModule {}
