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

// Import controller and service
import { SubAgentCommissionController } from './sub-agent-commission.controller';
import { SubAgentCommissionService } from './sub-agent-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 (11 different entities!)
import { VisaServiceMasterEntity } from 'src/entities/VisaServiceMaster.entity';
import { CollegeEntity } from 'src/entities/College.entity';
import { CountryEntity } from 'src/entities/Country.entity';
import { VmsVisaCasesEntity } from 'src/entities/VmsVisaCases.entity';
import { CourseMasterIntakeYearsEntity } from 'src/entities/CourseMasterIntakeYears.entity';
import { VcmCommissionContractInstancesEntity } from 'src/entities/VcmCommissionContractInstances.entity';
import { VcmSubAgentCommissionEntity } from 'src/entities/VcmSubAgentCommission.entity';
import { CompanyBankAccountEntity } from 'src/entities/CompanyBankAccount.entity';
import { B2bAffiliateAccountsEntity } from 'src/entities/B2bAffiliateAccounts.entity';
import { B2bAffiliateAccountBanksEntity } from 'src/entities/B2bAffiliateAccountBanks.entity';
import { FileService } from 'src/services/file.service';
import { VcmCommissionReceivedDetailsEntity } from 'src/entities/VcmCommissionReceivedDetails.entity';
import { VcmSubAgentCommissionDetailsEntity } from 'src/entities/VcmSubAgentCommissionDetails.entity';

/**
 * SubAgentCommissionModule - Feature module for comprehensive visa commission management
 *
 * This module encapsulates a sophisticated commission tracking system for education/visa services.
 * It integrates 11 different database entities representing a complete commission ecosystem.
 *
 * Business Domain: Education/Visa Consultancy Commission System
 * - Manages commissions for student visa applications
 * - Tracks relationships between multiple business entities
 * - Handles complex commission calculations and payments
 * - Integrates with visa case management and institute partnerships
 *
 * Module Characteristics:
 * - Multi-entity integration (11 entities across different domains)
 * - Complex business logic for commission calculations
 * - File upload support for documentation
 * - Caching for performance optimization
 * - Extensive reference data management
 */
@Module({
  /**
   * controllers - Array of controllers that handle HTTP requests
   *
   * SubAgentCommissionController: Provides 27+ endpoints for commission management
   * - Complete CRUD operations with file attachments
   * - Multiple reference data endpoints for dropdowns
   * - Advanced search and filtering
   * - Commission calculation and tracking
   * - File attachment management
   */
  controllers: [SubAgentCommissionController],

  /**
   * providers - Injectable services available within this module
   *
   * 1. SubAgentCommissionService: Core business logic for commission operations
   *    - Complex commission calculations and validations
   *    - Multi-entity joins and queries
   *    - Commission tracking and reconciliation
   *    - Audit trail management for financial transactions
   *
   * 2. FileService: Shared service for file operations
   *    - Handles file uploads, storage, and retrieval
   *    - Manages commission-related documentation
   *    - Provides file validation and security
   *    - Used for student documents, contracts, receipts
   */
  providers: [SubAgentCommissionService, FileService],

  /**
   * imports - External modules and dependencies required by this module
   *
   * 1. CacheModule.register(): Configures the caching system
   *    - Important for frequently accessed reference data
   *    - Caches countries, institutes, payment modes, etc.
   *    - Improves performance for dropdown population
   *
   * 2. TypeOrmModule.forFeature([...]): Registers 11 entities with TypeORM
   *    - Creates repositories for each entity
   *    - Enables complex joins across multiple tables
   *    - Supports transaction management across entities
   */
  imports: [
    CacheModule.register(), // Default cache configuration

    /**
     * TypeOrmModule.forFeature with 11 related entities:
     * This represents a complex ecosystem for visa commission management:
     */
    TypeOrmModule.forFeature([
      /**
       * 1. VcmSubAgentCommissionEntity (Core Entity)
       *    - Main commission transaction records
       *    - Stores commission amounts, dates, status
       *    - Contains foreign keys to all related entities
       *    - Likely includes: commission_id, amount, status, dates
       */
      VcmSubAgentCommissionEntity,

      /**
       * 2. VisaServiceMasterEntity (Service Reference)
       *    - Visa service types and products
       *    - Examples: Student Visa, Tourist Visa, Work Visa
       *    - Defines commission rates per service type
       *    - Used for service-specific commission calculations
       */
      VisaServiceMasterEntity,

      /**
       * 3. B2bAffiliateAccountsEntity (Sub-Agent/Affiliate Master)
       *    - Sub-agent/affiliate information
       *    - Contact details, agreement terms, status
       *    - Commission rates and payment terms
       *    - Used for commission recipient tracking
       */
      B2bAffiliateAccountsEntity,

      /**
       * 4. CountryEntity (Geographic Reference)
       *    - Country master data
       *    - Used for both service countries and client countries
       *    - May store commission variations by country
       *    - Supports multi-country commission structures
       */
      CountryEntity,

      /**
       * 5. CollegeEntity (Educational Institute Reference)
       *    - Educational institutions/colleges/universities
       *    - Institute details, rankings, locations
       *    - Commission agreements with specific institutes
       *    - Institute-specific commission rates
       */
      CollegeEntity,

      /**
       * 6. VmsVisaCasesEntity (Visa Case Management)
       *    - Individual visa application cases
       *    - Student/client information, application status
       *    - Links commissions to specific visa cases
       *    - Case details for commission validation
       */
      VmsVisaCasesEntity,

      /**
       * 7. CourseMasterIntakeYearsEntity (Academic Timeline)
       *    - Academic intakes and timelines
       *    - Examples: Fall 2024, Spring 2025
       *    - Intake-specific commission calculations
       *    - Used for commission timing and scheduling
       */
      CourseMasterIntakeYearsEntity,

      /**
       * 8. VcmCommissionContractInstancesEntity (Commission Rules)
       *    - Commission calculation rules and scenarios
       *    - Contract terms and conditions
       *    - Rate cards and calculation formulas
       *    - Instance-specific commission logic
       */
      VcmCommissionContractInstancesEntity,

      /**
       * 9. CompanyBankAccountEntity (Payment Source)
       *    - Company's bank accounts for payments
       *    - Source accounts for commission disbursement
       *    - Bank details, account numbers, balances
       *    - Used for payment processing
       */
      CompanyBankAccountEntity,

      /**
       * 10. B2bAffiliateAccountBanksEntity (Payment Destination)
       *     - Sub-agent's bank accounts for receiving payments
       *     - Destination accounts for commission payments
       *     - Multiple accounts per sub-agent
       *     - Used for payment routing
       */
      B2bAffiliateAccountBanksEntity,

      /**
       * 11. VcmCommissionReceivedDetailsEntity (Payment Tracking)
       *     - Commission payment receipt tracking
       *     - Records when commissions are actually paid/received
       *     - Payment confirmation and reconciliation
       *     - Audit trail for commission payments
       */
      VcmCommissionReceivedDetailsEntity,

      VcmSubAgentCommissionDetailsEntity, // Additional entity for detailed commission records
    ]),
  ],
})
export class SubAgentCommissionModule {}
