#!/bin/bash

checkConfigFilesMissingFiles()
{
    # Simply check if the configs directory exists and has some content
    if [ ! -d "$configs_dir" ]; then
        isError "Configs directory not found at $configs_dir"
        return 1
    fi

    local missing_files_count=0
    local found_files_count=0

    # Check for core config categories in the new structure
    for category in "${core_categories[@]}"; do
        local install_category_dir="$install_configs_dir/$category"
        local target_category_dir="$configs_dir/$category"
        
        if [ -d "$install_category_dir" ]; then
            # Create target category directory if it doesn't exist
            if [ ! -d "$target_category_dir" ]; then
                runInstallOp mkdir -p "$target_category_dir"
            fi
            
            # Check each file in the install category directory
            for install_file in "$install_category_dir"/*; do
                if [ -f "$install_file" ] && [[ ! "$install_file" =~ \.category$ ]]; then
                    local filename=$(basename "$install_file")
                    local target_file="$target_category_dir/$filename"
                    
                    if [ ! -f "$target_file" ]; then
                        # Copy missing file from install directory
                        runInstallOp cp "$install_file" "$target_file"
                        ((missing_files_count++))
                    fi
                    ((found_files_count++))
                fi
            done
        fi
    done

    if [ "$found_files_count" -gt 0 ]; then
        if [ "$missing_files_count" -gt 0 ]; then
            isSuccessful "$missing_files_count config files were missing and have been added to the configs folder."
        else
            isSuccessful "All config files are successfully set up in the configs folder."
        fi
    else
        isNotice "No configuration files found in install directory. This may be a fresh installation."
        exit
    fi
}
