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

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

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

// Import controller and service
import { SubAgentBonusPaidController } from './sub-agent-bonus-paid.controller';
import { SubAgentBonusPaidService } from './sub-agent-bonus-paid.service';

// Import shared file service for file operations
import { FileService } from 'src/services/file.service';

// Import multiple entity definitions for database tables
import { B2bAffiliateAccountsEntity } from 'src/entities/B2bAffiliateAccounts.entity';
import { VcmSubAgentBonusPaidEntity } from 'src/entities/VcmSubAgentBonusPaid.entity';
import { B2bAffiliateAccountBanksEntity } from 'src/entities/B2bAffiliateAccountBanks.entity';
import { CompanyBankAccountEntity } from 'src/entities/CompanyBankAccount.entity';
import { PaymentModeMasterEntity } from 'src/entities/PaymentModeMaster.entity';

/**
 * SubAgentBonusPaidModule - Feature module for sub-agent bonus payment management
 *
 * This module encapsulates all components related to bonus payment processing for sub-agents.
 * It integrates multiple database entities representing a complete financial transaction system.
 *
 * Business Domain: Commission/Bonus Management System
 * - Manages bonus payments from company to sub-agents/affiliates
 * - Tracks financial transactions with audit trails
 * - Handles file attachments for transaction proof
 * - Manages bank account information for both company and affiliates
 *
 * Module Characteristics:
 * - Multi-entity integration (5 different entities)
 * - File upload support via FileService
 * - Caching for performance optimization
 * - Complex business logic for financial transactions
 */
@Module({
  /**
   * controllers - Array of controllers that handle HTTP requests
   *
   * SubAgentBonusPaidController: Provides comprehensive bonus payment management endpoints
   * - CRUD operations for bonus payments
   * - File attachment management (upload/view/remove)
   * - Reference data endpoints (associates, banks, payment modes)
   * - Search and filtering with pagination
   */
  controllers: [SubAgentBonusPaidController],

  /**
   * providers - Injectable services available within this module
   *
   * 1. SubAgentBonusPaidService: Core business logic for bonus payment operations
   *    - Handles bonus payment creation, updates, and queries
   *    - Manages file attachments and storage
   *    - Performs financial calculations and validations
   *    - Implements audit trail for financial transactions
   *
   * 2. FileService: Shared service for file operations
   *    - Handles file uploads, storage, and retrieval
   *    - Manages file system or cloud storage operations
   *    - Provides file validation and security checks
   *    - Used for transaction screenshot/attachment management
   */
  providers: [SubAgentBonusPaidService, 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 (banks, payment modes, associates)
   *    - May cache search results for better performance
   *
   * 2. TypeOrmModule.forFeature([...]): Registers multiple entities with TypeORM
   *    - Creates repositories for each entity that can be injected into services
   *    - Enables complex joins and queries across related entities
   */
  imports: [
    CacheModule.register(), // Default cache configuration

    /**
     * TypeOrmModule.forFeature with 5 related entities:
     * This represents a complex domain model for financial bonus payments:
     */
    TypeOrmModule.forFeature([
      /**
       * 1. B2bAffiliateAccountsEntity - Sub-agent/Affiliate master data
       *    - Stores information about affiliates/sub-agents
       *    - Contains contact details, status, commission rates
       *    - Used for dropdowns and filtering in bonus payments
       */
      B2bAffiliateAccountsEntity,

      /**
       * 2. VcmSubAgentBonusPaidEntity - Main bonus payment transaction records
       *    - Core entity for bonus payment transactions
       *    - Stores payment amounts, dates, status, references
       *    - Contains foreign keys to other entities
       *    - Likely includes audit fields (created_by, modified_by)
       */
      VcmSubAgentBonusPaidEntity,

      /**
       * 3. CompanyBankAccountEntity - Company's bank accounts
       *    - Source accounts for bonus payments
       *    - Stores bank details, account numbers, balances
       *    - Used for "from" accounts in transactions
       */
      CompanyBankAccountEntity,

      /**
       * 4. B2bAffiliateAccountBanksEntity - Affiliate bank accounts
       *    - Destination accounts for bonus payments
       *    - Stores affiliate's bank details for payments
       *    - Each affiliate can have multiple bank accounts
       *    - Used for "to" accounts in transactions
       */
      B2bAffiliateAccountBanksEntity,

      /**
       * 5. PaymentModeMasterEntity - Payment method definitions
       *    - Reference table for payment methods
       *    - Examples: Bank Transfer, Cash, Check, Online Payment
       *    - Used for dropdowns and payment method validation
       */
      PaymentModeMasterEntity,
    ]),
  ],
})
export class SubAgentBonusPaidModule {}
