/*
    ! /configuration/mapping.js – Central Mapping Configuration
    ? This module maps system directories, and required dependencies for the ecosystem
*/

// % import nodejs packages
const path = require('path');
const fs = require('fs');
require('dotenv').config({ path: path.resolve(__dirname, '.env') });

// % declare directories
const rootDir = path.resolve(__dirname, '..');
const serverDir = path.resolve(rootDir, 'servers');
const dirs = {
    rootDir: rootDir,

    // § server directories
    serverDir: serverDir,
    gatewayDir: path.resolve(serverDir, 'gateway'),
    dashboardDir: path.resolve(serverDir, 'dashboard'),
    websocketDir: path.resolve(serverDir, 'websocket'),

    // § data structure directories
    configDir: path.resolve(rootDir, 'configuration'),
    dataDir: path.resolve(rootDir, 'database'),

    // § other directories
    serviceDir: path.resolve(rootDir, 'services'),
    interfaceDir: path.resolve(rootDir, 'ui')
};

// % declare database information
const databaseData = {
    host: process.env.INTERNAL_DATABASE_HOST,
    port: process.env.INTERNAL_DATABASE_PORT,
    users: {
        readonly: {
            user: process.env.DATABASE_READONLY_USER,
            pass: process.env.DATABASE_READONLY_PASS
        }
    },
    databases: {

    }
}

// $ parse all configuration files
const configFiles = fs.readdirSync(dirs.configDir).filter(file => 
    /\.config\.(js|json|ya?ml)$/.test(file)
);

// § export module
module.exports = {
    dirs,
    configFiles,
    databaseData
};