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

// Import controller and service
import { VisaCommissionController } from './visa-commission.controller';
import { VisaCommissionService } from './visa-commission.service';

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

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

// Import multiple entity definitions (13 unique entities, 15 total imports)
import { MenuActionsEntity } from 'src/entities/MenuActions.entity';
import { VisaServiceMasterEntity } from 'src/entities/VisaServiceMaster.entity';
import { CollegeEntity } from 'src/entities/College.entity';
import { MasteragentEntity } from 'src/entities/Masteragent.entity';
import { B2bAffiliateAccountsEntity } from 'src/entities/B2bAffiliateAccounts.entity';
import { CountryEntity } from 'src/entities/Country.entity';
import { CollegeCampusEntity } from 'src/entities/CollegeCampus.entity';
import { StudyLevelMasterEntity } from 'src/entities/StudyLevelMaster.entity';
import { VcmCommissionContractsEntity } from 'src/entities/VcmCommissionContracts.entity';
import { CourseMasterEntity } from 'src/entities/CourseMaster.entity';
import { VcmCommissionContractSetsEntity } from 'src/entities/VcmCommissionContractSets.entity';
import { FileService } from 'src/services/file.service';
import { VcmCommissionContractsHistoryEntity } from 'src/entities/VcmCommissionContractsHistory.entity';

/**
 * VisaCommissionModule - Feature module for comprehensive visa commission contract management
 *
 * This module encapsulates one of the most complex systems in the application,
 * managing commission contracts with educational institutes and agents. It integrates
 * 13 different database entities representing a complete contract management ecosystem.
 *
 * Business Domain: Visa Commission Contract Management System
 * - Manages commission contracts with educational institutes and agents
 * - Handles complex multi-level contract structures with specific terms
 * - Tracks contract history, edits, and status changes
 * - Manages contract documentation and file attachments
 * - Supports course-level commission configurations
 *
 * Module Characteristics:
 * - 13 entity integrations (15 total imports with duplicates)
 * - Complex business logic for contract management
 * - File upload support for contract documentation
 * - Caching for performance optimization
 * - Contract history and audit trail tracking
 *
 * Note: Some entities are imported twice (CourseMasterEntity, CollegeCampusEntity,
 * StudyLevelMasterEntity) - this might be a mistake or intentional for different contexts.
 */
@Module({
  /**
   * controllers - Array of controllers that handle HTTP requests
   *
   * VisaCommissionController: One of the most complex controllers with 28+ endpoints
   * - Complete contract lifecycle management (create, edit, view, delete)
   * - Complex file upload handling with multi-level field mapping
   * - Contract history tracking and audit trails
   * - Duplicate contract validation
   * - Status management and workflow control
   * - Multi-association type support (institutes vs agents)
   */
  controllers: [VisaCommissionController],

  /**
   * providers - Injectable services available within this module
   *
   * 1. VisaCommissionService: Extremely complex business logic service
   *    - Handles multi-level contract creation and management
   *    - Manages contract sets and specific terms
   *    - Implements duplicate contract validation
   *    - Tracks contract history and edits
   *    - Integrates with 13+ entity repositories
   *
   * 2. FileService: Shared service for file operations
   *    - Handles contract document uploads and management
   *    - Manages general and specific contract documents
   *    - Provides file validation and security
   *    - Used for contract compliance and documentation
   */
  providers: [VisaCommissionService, FileService],

  /**
   * imports - External modules and dependencies required by this module
   *
   * 1. CacheModule.register(): Configures the caching system
   *    - Provides in-memory caching for frequently accessed data
   *    - Important for reference data (countries, study levels, courses)
   *    - Reduces database load for complex contract queries
   *
   * 2. TypeOrmModule.forFeature([...]): Registers 13 entities with TypeORM
   *    - Creates repositories for each entity
   *    - Enables complex multi-entity joins for contract management
   *    - Supports transaction management for contract operations
   */
  imports: [
    CacheModule.register(), // Default cache configuration

    /**
     * TypeOrmModule.forFeature with 13 unique entities (15 total imports):
     * This represents a comprehensive contract management ecosystem
     */
    TypeOrmModule.forFeature([
      /**
       * 1. MenuActionsEntity (Access Control)
       *    - Menu permissions and actions
       *    - Likely used for role-based access to commission features
       *    - Controls who can create/edit/view contracts
       */
      MenuActionsEntity,

      /**
       * 2. VisaServiceMasterEntity (Service Reference)
       *    - Visa service types and products
       *    - Examples: Student Visa (ID: 8), Tourist Visa, Work Visa
       *    - Defines which services have commission contracts
       */
      VisaServiceMasterEntity,

      /**
       * 3. CollegeEntity (Educational Institute Reference)
       *    - Educational institutions/colleges/universities
       *    - Institute details, rankings, locations
       *    - Primary contract partners for commission agreements
       */
      CollegeEntity,

      /**
       * 4. MasteragentEntity (Master Agent Reference)
       *    - Master/primary agents or partners
       *    - Alternative contract partners to institutes
       *    - Agent details, contract terms, status
       */
      MasteragentEntity,

      /**
       * 5. B2bAffiliateAccountsEntity (B2B Affiliate Reference)
       *    - Business-to-business affiliate accounts
       *    - May represent another type of contract partner
       *    - Affiliate details and commission structures
       */
      B2bAffiliateAccountsEntity,

      /**
       * 6. CountryEntity (Geographic Reference)
       *    - Country master data
       *    - Used for both service countries and client countries
       *    - Geographic scope for commission contracts
       */
      CountryEntity,

      /**
       * 7. CollegeCampusEntity (Institute Campus Reference) - Imported twice
       *    - Specific campuses of educational institutes
       *    - Campus details, locations, facilities
       *    - Allows campus-specific commission agreements
       *    - Duplicate import might be intentional for different contexts
       */
      CollegeCampusEntity,

      /**
       * 8. StudyLevelMasterEntity (Academic Level Reference) - Imported twice
       *    - Academic study levels
       *    - Examples: Undergraduate, Postgraduate, Diploma, Certificate
       *    - Study level-specific commission rates
       *    - Duplicate import might be intentional for different contexts
       */
      StudyLevelMasterEntity,

      /**
       * 9. VcmCommissionContractsEntity (Core Contract Entity)
       *    - Main commission contract records
       *    - Stores contract terms, dates, status, parties
       *    - Contains foreign keys to associate, product, countries
       *    - Likely includes: contract_id, terms, effective_date, status
       */
      VcmCommissionContractsEntity,

      /**
       * 10. CourseMasterEntity (Educational Course Reference) - Imported twice
       *     - Educational courses/programs offered by institutes
       *     - Course details, duration, fees, requirements
       *     - Course-specific commission configurations
       *     - Duplicate import might be intentional for different contexts
       */
      CourseMasterEntity,

      /**
       * 11. VcmCommissionContractSetsEntity (Contract Terms Sets)
       *     - Groups of contract terms and conditions
       *     - Allows organizing commission rules into sets
       *     - May include multiple commission calculation rules
       *     - Linked to main contract entity
       */
      VcmCommissionContractSetsEntity,

      /**
       * 12. VcmCommissionContractsHistoryEntity (Contract Audit Trail)
       *     - Tracks all changes to commission contracts
       *     - Full history of contract edits and status changes
       *     - Audit trail for compliance and dispute resolution
       *     - Includes before/after values for all changes
       */
      VcmCommissionContractsHistoryEntity,

      // Duplicate imports (likely intentional for different query contexts):
      CourseMasterEntity, // Duplicate of #10
      CollegeCampusEntity, // Duplicate of #7
      StudyLevelMasterEntity, // Duplicate of #8
    ]),
  ],
})
export class VisaCommissionModule {}
