import { Module } from '@nestjs/common';
import { VisaCommissionEnquiryController } from './visa-commission-enquiry.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { VisaCommissionEnquiryService } from './visa-commission-enquiry.service';
import { CacheModule } from '@nestjs/cache-manager';
import { VisaServiceMasterEntity } from 'src/entities/VisaServiceMaster.entity';
import { CollegeEntity } from 'src/entities/College.entity';
import { MasteragentEntity } from 'src/entities/Masteragent.entity';
import { CountryEntity } from 'src/entities/Country.entity';
import { VcmInstituteCommissionEnquiryEntity } from 'src/entities/VcmInstituteCommissionEnquiry.entity';
import { VcmMasterAgentCommissionEnquiryEntity } from 'src/entities/VcmMasterAgentCommissionEnquiry.entity';
import { VmsVisaCasesEntity } from 'src/entities/VmsVisaCases.entity';
import { CourseMasterIntakeYearsEntity } from 'src/entities/CourseMasterIntakeYears.entity';
import { VcmCommissionContractInstancesEntity } from 'src/entities/VcmCommissionContractInstances.entity';
import { VmsCaseOfferLetterInstancesEntity } from 'src/entities/VmsCaseOfferLetterInstances.entity';
import { VcmInstituteCommissionEnquiryDetailsEntity } from 'src/entities/VcmInstituteCommissionEnquiryDetails.entity';
import { CenterLocationEntity } from 'src/entities/CenterLocation.entity';
import { CompanyBankAccountEntity } from 'src/entities/CompanyBankAccount.entity';
import { CommissionDetailsTransformer } from '../course-portal/transformers/commission-details.transform';
import { VcmCommissionResponseReasonEntity } from 'src/entities/VcmCommissionResponseReason.entity';
import { VcmCommissionDifferenceReasonEntity } from 'src/entities/VcmCommissionDifferenceReason.entity';
import { VcmMasterAgentCommissionEnquiryDetailsEntity } from 'src/entities/VcmMasterAgentCommissionEnquiryDetails.entity';
import { VcmCommissionReceivedDetailsEntity } from 'src/entities/VcmCommissionReceivedDetails.entity';
import { VcmCommissionInvoiceEntity } from 'src/entities/VcmCommissionInvoice.entity';
import { VcmSubAgentCommissionDetailsEntity } from 'src/entities/VcmSubAgentCommissionDetails.entity';

/**
 * VisaCommissionEnquiryModule - Feature module for visa commission enquiry management
 *
 * This module encapsulates all components related to commission enquiries for visa cases.
 * It supports two parallel workflow paths:
 * 1. Institute-based commission enquiries (for educational institutions)
 * 2. Master Agent-based commission enquiries (for partner agents)
 *
 * Business Domain: Visa Commission Tracking & Reconciliation System
 * - Tracks commission enquiries sent to institutes and agents
 * - Manages commission responses and negotiations
 * - Handles commission receipt and reconciliation
 * - Supports invoicing and payment tracking
 * - Provides comprehensive reporting and audit trails
 *
 * Module Characteristics:
 * - 18 entity integrations covering all aspects of commission management
 * - Dual workflow support (institute vs master agent)
 * - Financial transaction tracking with invoice support
 * - Commission calculation and validation
 * - Response and difference reason management
 *
 * Architecture: Service-oriented with comprehensive entity relationships
 * - Primary entities: Commission enquiries (institute & master agent)
 * - Supporting entities: Visa cases, contracts, intake years, financial data
 * - Reference entities: Countries, response reasons, bank accounts
 */
@Module({
  /**
   * controllers - Array of controllers that handle HTTP requests
   *
   * VisaCommissionEnquiryController: Provides comprehensive commission enquiry management
   * - 30+ endpoints for CRUD operations and filtering
   * - Dual workflow support (institute vs master agent)
   * - File attachment management for payment proofs
   * - Commission calculation and reconciliation endpoints
   * - Reference data endpoints for dropdown population
   */
  controllers: [VisaCommissionEnquiryController],

  /**
   * providers - Injectable services and utilities available within this module
   *
   * 1. VisaCommissionEnquiryService: Core business logic for commission enquiries
   *    - Dual workflow management (institute & master agent)
   *    - Complex commission calculations and validations
   *    - Financial transaction processing and reconciliation
   *    - Integration with 18 different entity repositories
   *    - Commission response and receipt management
   *
   * 2. CommissionDetailsTransformer: Data transformation utility
   *    - Transforms raw commission data for display
   *    - Formats commission calculations and summaries
   *    - Used in reporting and UI display layers
   *    - May handle currency formatting and localization
   */
  providers: [VisaCommissionEnquiryService, CommissionDetailsTransformer],

  /**
   * 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, response reasons, institutes)
   *    - Reduces database load for filter dropdown population
   *    - Improves response times for commission calculations
   *
   * 2. TypeOrmModule.forFeature([...]): Registers 18 entities with TypeORM
   *    - Creates repositories for each entity that can be injected into services
   *    - Enables complex queries across multiple related entities
   *    - Supports transaction management for financial operations
   *    - Facilitates commission calculation with multiple joins
   */
  imports: [
    CacheModule.register(), // Default cache configuration for performance optimization

    /**
     * TypeOrmModule.forFeature with 18 related entities:
     * This represents a comprehensive commission enquiry tracking system
     * organized into logical groups:
     */
    TypeOrmModule.forFeature([
      // ==================== CORE COMMISSION ENQUIRY ENTITIES ====================
      /**
       * 1. VcmInstituteCommissionEnquiryEntity (Institute Commission Enquiry - Main)
       *    - Primary entity for institute-based commission enquiries
       *    - Stores enquiry metadata, status, dates
       *    - Contains institute reference and enquiry details
       *    - Example: "XYZ University - Q1 2024 Commission Enquiry"
       */
      VcmInstituteCommissionEnquiryEntity,

      /**
       * 2. VcmMasterAgentCommissionEnquiryEntity (Master Agent Commission Enquiry - Main)
       *    - Primary entity for master agent-based commission enquiries
       *    - Parallel to institute enquiries but for agent relationships
       *    - Stores agent-specific enquiry data and status
       *    - Example: "ABC Agency - Student Visa Commission Enquiry"
       */
      VcmMasterAgentCommissionEnquiryEntity,

      // ==================== REFERENCE AND SUPPORTING ENTITIES ====================
      /**
       * 3. VisaServiceMasterEntity (Visa Service Reference)
       *    - Visa service types and products
       *    - Defines which visa services are eligible for commissions
       *    - Used for service-specific commission calculations
       *    - Examples: Student Visa, Work Visa, Tourist Visa
       */
      VisaServiceMasterEntity,

      /**
       * 4. MasteragentEntity (Master Agent Reference)
       *    - Master/primary agents or partners
       *    - Agent details, contract terms, commission rates
       *    - Used for agent-specific commission calculations
       *    - Contains agent hierarchy and relationship information
       */
      MasteragentEntity,

      /**
       * 5. CountryEntity (Country Reference)
       *    - Global country data
       *    - Used for client nationality-based commission calculations
       *    - Supports multi-country commission structures
       *    - Country-specific commission rates and rules
       */
      CountryEntity,

      /**
       * 6. CollegeEntity (Educational Institute Reference)
       *    - Educational institutions/colleges/universities
       *    - Institute details, rankings, commission agreements
       *    - Used for institute-specific commission calculations
       *    - Institute hierarchy and campus relationships
       */
      CollegeEntity,

      // ==================== VISA CASE AND CONTRACT ENTITIES ====================
      /**
       * 7. VmsVisaCasesEntity (Visa Case Management)
       *    - Individual visa application cases
       *    - Links students to institutes and visa services
       *    - Contains case status, dates, and financial information
       *    - Used for commission calculations per case basis
       */
      VmsVisaCasesEntity,

      /**
       * 8. CourseMasterIntakeYearsEntity (Academic Intake Reference)
       *    - Academic intake periods and years
       *    - Used for commission calculations based on intake timing
       *    - Supports seasonal commission variations
       *    - Intake-specific commission rates and terms
       */
      CourseMasterIntakeYearsEntity,

      /**
       * 9. VcmCommissionContractInstancesEntity (Commission Contract Details)
       *    - Specific commission contract tiers and structures
       *    - Contains commission rates, percentages, amounts
       *    - Used for commission calculation against contract terms
       *    - Supports tiered commission structures
       */
      VcmCommissionContractInstancesEntity,

      /**
       * 10. VmsCaseOfferLetterInstancesEntity (Offer Letter Details)
       *     - Individual offer letters for visa cases
       *     - Contains course details, fees, and acceptance information
       *     - Used for commission calculations based on course fees
       *     - Links commissions to specific offer terms
       */
      VmsCaseOfferLetterInstancesEntity,

      // ==================== DETAILED COMMISSION ENQUIRY ENTITIES ====================
      /**
       * 11. VcmInstituteCommissionEnquiryDetailsEntity (Institute Enquiry Details)
       *     - Detailed line items for institute commission enquiries
       *     - Contains per-case commission calculations
       *     - Stores expected vs actual commission amounts
       *     - Used for detailed enquiry analysis and reconciliation
       */
      VcmInstituteCommissionEnquiryDetailsEntity,

      /**
       * 12. VcmMasterAgentCommissionEnquiryDetailsEntity (Master Agent Enquiry Details)
       *     - Detailed line items for master agent commission enquiries
       *     - Parallel to institute enquiry details but for agents
       *     - Contains agent-specific commission calculations
       *     - Used for agent commission reconciliation
       */
      VcmMasterAgentCommissionEnquiryDetailsEntity,

      // ==================== FINANCIAL AND INVOICING ENTITIES ====================
      /**
       * 13. CenterLocationEntity (Business Center/Location Reference)
       *     - Company business centers or branches
       *     - Used for invoice generation and financial reporting
       *     - Location-specific commission processing
       *     - Branch-level commission tracking and reporting
       */
      CenterLocationEntity,

      /**
       * 14. CompanyBankAccountEntity (Bank Account Reference)
       *     - Company's bank accounts for commission payments
       *     - Used for payment processing and reconciliation
       *     - Account details, verification status, currency
       *     - Multi-currency commission payment support
       */
      CompanyBankAccountEntity,

      /**
       * 15. VcmCommissionInvoiceEntity (Commission Invoicing)
       *     - Generated invoices for commission payments
       *     - Contains invoice details, amounts, due dates
       *     - Supports invoice tracking and payment reconciliation
       *     - Used for financial reporting and audit trails
       */
      VcmCommissionInvoiceEntity,

      // ==================== RESPONSE AND REASON ENTITIES ====================
      /**
       * 16. VcmCommissionResponseReasonEntity (Response Reason Reference)
       *     - Predefined reasons for commission enquiry responses
       *     - Standardized response categories for tracking
       *     - Examples: "Commission Paid", "Under Review", "Disputed"
       *     - Used for response categorization and reporting
       */
      VcmCommissionResponseReasonEntity,

      /**
       * 17. VcmCommissionDifferenceReasonEntity (Difference Reason Reference)
       *     - Predefined reasons for commission amount differences
       *     - Explains variances between expected and actual commissions
       *     - Examples: "Service Fee Deduction", "Exchange Rate Variance"
       *     - Used for discrepancy tracking and resolution
       */
      VcmCommissionDifferenceReasonEntity,

      // ==================== COMMISSION RECEIVED AND SUB-AGENT ENTITIES ====================
      /**
       * 18. VcmCommissionReceivedDetailsEntity (Commission Receipt Tracking)
       *     - Records of actual commission payments received
       *     - Contains payment details, dates, amounts
       *     - Supports partial payments and installment tracking
       *     - Used for payment reconciliation and cash flow tracking
       */
      VcmCommissionReceivedDetailsEntity,

      /**
       * 19. VcmSubAgentCommissionDetailsEntity (Sub-Agent Commission Details)
       *     - Commission details for sub-agents (under master agents)
       *     - Supports multi-level agent commission structures
       *     - Contains sub-agent specific commission calculations
       *     - Used for agent hierarchy commission distribution
       */
      VcmSubAgentCommissionDetailsEntity,
    ]),
  ],
})
export class VisaCommissionEnquiryModule {}
