'use strict';
import { systemCommands } from '../constants/npm-commands.js';
import { environmentVariables, ciLogMessages } from '../constants/ci-constants.js';
import { execSyncCommand } from '../tools/exec.js';
import { getDropDatabaseCommand } from '../tools/npm-command-funcs.js';
import { createEarlyInfraError } from '../tools/create-early-infra-error.js';
import { cliLogError, cliLogSubtitle } from '../../../fd-toolbox/logging/cli-logger.js';
import { commandNames } from '../../../base-repo/app-constants/command-names.js';
import { stdioStatuses } from '../../../base-repo/constants/tools-constants.js';
import { getStringEnvSetting } from '../../../fd-toolbox/infra/env-functions.js';

var __defProp=Object['defineProperty'],__name=(_0x4b3a15,_0x3c4e09)=>__defProp(_0x4b3a15,'name',{'value':_0x3c4e09,'configurable':!![]});function cleanup(){ensureSystemDependencies();const _0x128537=environmentVariables['databaseUrl'],_0x5028cd=getStringEnvSetting(environmentVariables['databaseUrl']),_0x53e87d=getStringEnvSetting(environmentVariables['databaseName']);if(!_0x5028cd||!_0x53e87d){const _0x3381a9='Cleanup\x20failed:\x20Required\x20environment\x20variables\x20are\x20not\x20set.\x20\x27'+_0x128537+ciLogMessages['quotedOrQuoted']+environmentVariables['databaseName']+'\x27\x20is\x20missing.';cliLogError(_0x3381a9);throw createEarlyInfraError(_0x3381a9);}cliLogSubtitle('Dropping\x20database:\x20'+_0x53e87d);const _0x35c6c9=getDropDatabaseCommand(_0x5028cd,_0x53e87d);execSyncCommand(_0x35c6c9);}__name(cleanup,'cleanup');function ensureSystemDependencies(){const _0x522921=[];try{execSyncCommand(systemCommands['checkGit'],{'stdio':stdioStatuses['ignore']});}catch{cliLogSubtitle('\x27git\x27\x20not\x20found,\x20scheduling\x20for\x20installation.'),_0x522921['push'](commandNames['git']);}try{execSyncCommand(systemCommands['checkPsql'],{'stdio':stdioStatuses['ignore']});}catch{cliLogSubtitle('\x27psql\x27\x20not\x20found,\x20scheduling\x20for\x20installation.'),_0x522921['push']('postgresql-client');}if(_0x522921['length']>-0x1*0x719+-0x1a35*0x1+0x214e){cliLogSubtitle('Updating\x20package\x20list...'),execSyncCommand(systemCommands['aptUpdate']);const _0x4f2bd7=_0x522921['join']('\x20');cliLogSubtitle('Installing\x20missing\x20packages:\x20'+_0x4f2bd7+'...'),execSyncCommand('apt-get\x20install\x20-y\x20'+_0x4f2bd7);}else cliLogSubtitle('All\x20system\x20dependencies\x20are\x20already\x20installed.');}__name(ensureSystemDependencies,'ensureSystemDependencies');

export { cleanup };
