/**
 *   |██████         |██████         |██████
 *   |██    |██    |██      |██    |██      |██
 *   |██    |██    |██             |██
 *   |██    |██      |██████         |██████
 *   |██    |██             |██             |██
 *   |██    |██    |██      |██    |██      |██
 *   |██████         |██████          |██████
 *
 * # DSS Sound System Configuration
 *
 * This configuration file manages the settings for the DSS Sound System, enabling background music
 * and various sound effects triggered by specific in-game events. Developers can easily
 * customize which sounds play, adjust their properties, and define new sound-triggering events.
 *
 * ## Table of Contents
 * 1. [Debug Settings](#debug-settings)
 * 2. [General Settings](#general-settings)
 * 3. [Sound Definitions](#sound-definitions)
 *    - [Background Music](#background-music)
 *    - [Event-Based Sounds](#event-based-sounds)
 *    - [Proximity-Based Sounds](#proximity-based-sounds)
 * 4. [Tag-Based Sound Definitions](#tag-based-sound-definitions)

 *
 * ### 3. Sound Definitions
 *
 * Define all sounds used in the system, categorized by their triggering events.
 *
 * #### Background Music (`BG_SOUND`)
 *
 * Controls the background music playback.
 *
 * - `PLAY`: Enable or disable the background music.
 * - `DEBUG`: Enable debugging for background music.
 * - `EVENT`: The event that triggers the background music.
 * - `SOUND`: Array of sound identifiers for variety.
 * - `VOLUME`: Playback volume (0.0 to 1.0).
 * - `PITCH`: Playback pitch.
 * - `LOOPED`: Whether the music loops.
 *
 * ```javascript
 * BG_SOUND: { 
 *   PLAY: false,
 *   DEBUG: false,
 *   EVENT: "playerSpawn", 
 *   SOUND: ["dss_sound.horror_bg", "dss_sound.extra_fad"],
 *   VOLUME: 0.4, 
 *   PITCH: 1.0, 
 *   LOOPED: true
 * },
 * ```
 *
 * #### Event-Based Sounds
 *
 * Sounds triggered by specific in-game events such as interactions or entity actions.
 *
 * Each sound definition includes:
 * - `PLAY`: Enable or disable the sound.
 * - `DEBUG`: Enable debugging for this sound.
 * - `EVENT`: The in-game event that triggers the sound.
 * - Additional properties based on the event type (e.g., `BLOCK`, `ITEM`, `ENTITY`).
 * - `SOUND`: Sound identifier.
 * - `VOLUME`: Playback volume.
 * - `PITCH`: Playback pitch.
 * - `LOOPED`: Whether the sound loops.
 *
 * **Examples:**
 *
 * - **Door Interaction Sound**
 *
 * ```javascript
 * DOOR_SOUND: {  
 *   PLAY: true,
 *   DEBUG: false,
 *   EVENT: "blockInteract", 
 *   BLOCK: "minecraft:wooden_door", 
 *   SOUND: "dss_sound.horror_whispers2",  
 *   VOLUME: 1.0,  
 *   PITCH: 1.0, 
 *   LOOPED: false 
 * },
 * ```
 *
 * - **Zombie Hurt Sound**
 *
 * ```javascript
 * ZOMBIE_HURT_SOUND: {  
 *   PLAY: true,
 *   DEBUG: true,
 *   EVENT: "entityHurt", 
 *   ENTITY: "minecraft:zombie",
 *   SOUND: "dss_sound.horror_scream1",  
 *   VOLUME: 1.0,  
 *   PITCH: 1.0, 
 *   LOOPED: false 
 * },
 * ```
 *
 * #### Proximity-Based Sounds
 *
 * Sounds that trigger based on the player's proximity to specific entities.
 *
 * - `PLAY`: Enable or disable the proximity sound.
 * - `DEBUG`: Enable debugging for proximity sounds.
 * - `EVENT`: Always set to `"proximity"` for these sounds.
 * - `ENTITY`: The target entity to monitor.
 * - `SOUND`: Sound identifier.
 * - `BASE_VOLUME`: Base volume before distance attenuation.
 * - `BASE_PITCH`: Base pitch before adjustments.
 * - `UPDATE_INTERVAL`: Frequency (in ticks) to update sound based on distance.
 * - `MIN_DELAY`: Minimum delay between sound triggers.
 * - `MAX_SOUND_DISTANCE`: Override the default maximum distance for this sound.
 *
 * ```javascript
 * PROXIMITY1: {   
 *   PLAY: false,
 *   DEBUG: false,
 *   EVENT: "proximity",
 *   ENTITY: "minecraft:zombie",
 *   SOUND: "dss_sound.horror_heartbeat",   
 *   BASE_VOLUME: 0.3, 
 *   BASE_PITCH: 0.3,
 *   UPDATE_INTERVAL: 20,
 *   MIN_DELAY: 20,
 *   MAX_SOUND_DISTANCE: 20
 * },
 * ```
 *
 * *You can add more proximity-based sounds by following the structure above.*
 *
 * ### 4. Tag-Based Sound Definitions
 *
 * Sounds that trigger based on specific tags applied to players or entities.
 *
 * Each tag definition includes:
 * - `PLAY`: Enable or disable the tag-based sound.
 * - `DEBUG`: Enable debugging for this tag.
 * - `TAGNAME`: The name of the tag to monitor.
 * - `SOUNDNAME`: Sound identifier to play.
 * - `VOLUME`: Playback volume.
 * - `PITCH`: Playback pitch.
 * - `PLAYTIMES`: Number of times the sound plays (use a high number or specific logic for looping).
 * - `COOLDOWN`: Delay (in ticks) before the sound can be played again.
 * - `PRIORITY`: Determines the order of sound playback when multiple tags are active.
 *
 * **Examples:**
 *
 * - **Whispered Tag Sound**
 *
 * ```javascript
 * whispered: {
 *   PLAY: true,
 *   DEBUG: false,
 *   TAGNAME: "whispered",
 *   SOUNDNAME: "dss_sound.horror_whispers1",
 *   VOLUME: 1.0,
 *   PITCH: 1.0,
 *   PLAYTIMES: 1,
 *   COOLDOWN: 1000,
 *   PRIORITY: 1
 * },
 * ```
 *
 * - **Noticed Tag Sound**
 *
 * ```javascript
 * noticed: {
 *   PLAY: true,
 *   DEBUG: false,
 *   TAGNAME: "noticed",
 *   SOUNDNAME: "dss_sound.horror_psst1",
 *   VOLUME: 1.0,
 *   PITCH: 1.0,
 *   PLAYTIMES: 3,
 *   COOLDOWN: 2000,
 *   PRIORITY: 2
 * },
 * ```
 *
 * *Add more tag-based sounds by following the structure above.*
 */

 // dss_sound_config.js
 export const CONFIG = {
  /**
   * ## Debug Settings
   * Toggle various debugging logs to assist in development and troubleshooting.
   */
  DEBUG: { 
    ALL: false,          // Enables all debug logs
    BG_MUSIC: false,     // Logs related to background music
    SOUND_EFFECT: false, // Logs for sound effects
    PROXIMITY: false,    // Debugging for proximity-based sounds
    TAGGING: false       // Debugging for tag-based sounds
  },
  
  /**
   * ## General Settings
   * Configure general behavior of the sound system.
   */
  UPDATE_INTERVAL: 60,          // Frequency (in ticks) for general sound updates
  HEARTBEAT_UPDATE_INTERVAL: 15, // Interval for heartbeat updates (deprecated)
  MAX_SOUND_DISTANCE: 20,        // Default maximum distance for proximity-based sounds
  TAG_CHECK_INTERVAL: 10,        // Ticks between checks for player tags
  
  /**
   * ## Sound Definitions
   * Define all sounds used in the system, categorized by their triggering events.
   */
  SOUNDS: {
    /**
     * -----------------------------------------------------------------------------------------------------
     * ## Tag-Based Sound Definitions
     * Sounds that trigger based on specific tags applied to players or entities.
     */

    // PLAYER_STATE: {
    //   "idle": {
    //     PLAY: true,
    //     SOUNDS: ["lobby_music"],
    //     REMOVE: ["battle_mode"]
    //   },
    //   "battle": {
        
    //   }
    // },
    
    // TAG_BUNDLES: {
    //   "battle_mode": {
    //     PLAY: true,
    //     SOUNDS: ["whispered", "noticed"],
    //     REMOVE: ["lobby_music"]
    //   }
    // },

    // TAGS: {
    TAGS: {

      lobby: {
        PLAY: true,                                       // Enable or disable the tag-based sound
        DEBUG: false,                                     // Enable debugging for this tag
        TAGNAME: "lobby",                             // Name of the tag to monitor
        SOUNDNAME: "lobby",          // Sound identifier to play
        VOLUME: 0.1,                                      // Playback volume
        PITCH: 1.0,                                       // Playback pitch
        PLAYTIMES: 0,                                     // Number of times the sound plays (1 = once, 0 = loop until tag removed)
        COOLDOWN: 180,                                      // Delay between sound repetitions and cooldown to prevent spam (seconds)
        PRIORITY: 1                                       // Priority level (higher means higher priority)
      },
      clear: {
        PLAY: true,                                       // Enable or disable the tag-based sound
        DEBUG: false,                                     // Enable debugging for this tag
        TAGNAME: "clear",                             // Name of the tag to monitor
        SOUNDNAME: "clear",          // Sound identifier to play
        VOLUME: 0.1,                                      // Playback volume
        PITCH: 1.0,                                       // Playback pitch
        PLAYTIMES: 0,                                     // Number of times the sound plays (1 = once, 0 = loop until tag removed)
        COOLDOWN: 60,                                      // Delay between sound repetitions and cooldown to prevent spam (seconds)
        PRIORITY: 1                                       // Priority level (higher means higher priority)
      },
      floor: {
        PLAY: true,                                       // Enable or disable the tag-based sound
        DEBUG: false,                                     // Enable debugging for this tag
        TAGNAME: "level",                             // Name of the tag to monitor
        SOUNDNAME: "level",          // Sound identifier to play
        VOLUME: 0.1,                                      // Playback volume
        PITCH: 1.0,                                       // Playback pitch
        PLAYTIMES: 0,                                     // Number of times the sound plays (1 = once, 0 = loop until tag removed)
        COOLDOWN: 660,                                      // Delay between sound repetitions and cooldown to prevent spam (seconds)
        PRIORITY: 1                                       // Priority level (higher means higher priority)
      },
      // Add more tag-based sounds here following the structure above...
    },

    /**
     * -----------------------------------------------------------------------------------------------------
     * ### Background Music
     * Controls the background music playback.
     */
    // BG_SOUND: { 
    //   PLAY: false,                                      // Enable or disable background music
    //   DEBUG: false,                                     // Enable debugging for background music
    //   EVENT: "playerSpawn",                             // Event that triggers the background music
    //   SOUND: ["dss_sound.horror_bg", "dss_sound.extra_fad"], // Array of sound identifiers for variety
    //   VOLUME: 0.4,                                      // Playback volume (0.0 to 1.0)
    //   PITCH: 1.0,                                       // Playback pitch
    //   LOOPED: true                                      // Whether the music loops
    // }, 
    
    /**
     * -----------------------------------------------------------------------------------------------------
     * ### Event-Based Sounds
     * Sounds triggered by specific in-game events such as interactions or entity actions.
     */
    
    // Door Interaction Sound
    // SAMPLE_BLOCK_INTERACT_SOUND: {  
    //   PLAY: false,                                       // Enable or disable the door sound
    //   DEBUG: false,                                     // Enable debugging for this sound
    //   EVENT: "blockInteract",                           // Event type that triggers the sound
    //   BLOCK: "minecraft:wooden_door",                   // Specific block that triggers the sound
    //   SOUND: "dss_sound.horror_whispers2",              // Sound identifier
    //   VOLUME: 1.0,                                      // Playback volume
    //   PITCH: 1.0,                                       // Playback pitch
    //   LOOPED: false                                     // Whether the sound loops
    // }, 
    
    // // Fishing Rod Use Sound
    // SAMPLE_ITEM_USE_SOUND: {  
    //   PLAY: false,                                       // Enable or disable the fishing rod sound
    //   DEBUG: false,                                     // Enable debugging for this sound
    //   EVENT: "itemUse",                                 // Event type that triggers the sound
    //   ITEM: "minecraft:fishing_rod",                    // Specific item that triggers the sound
    //   SOUND: "dss_sound.horror_whispers1",              // Sound identifier
    //   VOLUME: 1.0,                                      // Playback volume
    //   PITCH: 1.0,                                       // Playback pitch
    //   LOOPED: false                                     // Whether the sound loops
    // },
    
    // // Zombie Hurt Sound
    // SAMPLE_ENTITY_HURT_SOUND: {  
    //   PLAY: false,                                       // Enable or disable the zombie hurt sound
    //   DEBUG: true,                                      // Enable debugging for this sound
    //   EVENT: "entityHurt",                              // Event type that triggers the sound
    //   ENTITY: "minecraft:zombie",                        // Specific entity that triggers the sound
    //   SOUND: "dss_sound.horror_scream1",                // Sound identifier
    //   VOLUME: 1.0,                                      // Playback volume
    //   PITCH: 1.0,                                       // Playback pitch
    //   LOOPED: false                                     // Whether the sound loops
    // },
    
    /**
     * -----------------------------------------------------------------------------------------------------
     * ### Proximity-Based Sounds ( NOT FULLY-IMPLEMENTED YET )
     * Sounds that trigger based on the player's proximity to specific entities.
     */
    
    // PROXIMITY1: {   
    //   PLAY: false,                                      // Enable or disable the proximity sound
    //   DEBUG: false,                                     // Enable debugging for proximity sounds
    //   EVENT: "proximity",                               // Event type (always "proximity" for these sounds)
    //   ENTITY: "minecraft:zombie",                        // Target entity to monitor
    //   SOUND: "dss_sound.horror_heartbeat",              // Sound identifier
    //   BASE_VOLUME: 0.3,                                 // Base volume before distance attenuation
    //   BASE_PITCH: 0.3,                                  // Base pitch before adjustments
    //   UPDATE_INTERVAL: 20,                              // Frequency (in ticks) to update sound based on distance
    //   MIN_DELAY: 20,                                     // Minimum delay (in ticks) between sound triggers
    //   MAX_SOUND_DISTANCE: 20                            // Override the default maximum distance if needed
    // },
    // Add more proximity sounds here following the structure above...
  },
}; 

// Add configuration validation
export function validateConfig(config) {
  const errors = [];
  
  // Validate required fields
  if (!config.SOUNDS) errors.push('Missing SOUNDS configuration');
  
  // Validate sound entries
  for (const [key, sound] of Object.entries(config.SOUNDS)) {
    if (!sound.EVENT) errors.push(`Missing EVENT for sound ${key}`);
    if (sound.VOLUME && (sound.VOLUME < 0 || sound.VOLUME > 1)) {
      errors.push(`Invalid VOLUME for sound ${key}`);
    }
    // ... other validations
  }

  if (errors.length > 0) {
    throw new Error(`Configuration validation failed:\n${errors.join('\n')}`);
  }
} 
