'use strict';
import _0x297387 from 'pg-boss';
import { logWarning, logInfo } from '../../../../fd-toolbox/server/logging/logger.js';
import { getDbType, getDbConnectionString } from '../../../db/db-config.js';
import { dbTypes } from '../../../../base-repo/constants/tools-constants.js';
import { emptyUuid } from '../../../../fd-toolbox/constants/constants.js';

var __defProp=Object['defineProperty'],__name=(_0x3a1406,_0x35da1b)=>__defProp(_0x3a1406,'name',{'value':_0x35da1b,'configurable':!![]});let jobManager;const currentDbType=getDbType();currentDbType===dbTypes['postgres']?jobManager=new _0x297387(getDbConnectionString()):logWarning('[BackgroundJobs]\x20Running\x20in\x20STUB\x20mode.\x20Database\x20\x27'+currentDbType+'\x27\x20is\x20not\x20supported\x20by\x20PgBoss.');async function startBackgroundJobs(){if(!jobManager){logInfo('['+currentDbType+']\x20Background\x20Jobs\x20Manager\x20started\x20(Stub\x20Mode)');return;}await jobManager['start']();}__name(startBackgroundJobs,'startBackgroundJobs');async function stopBackgroundJobs(){if(!jobManager){logInfo('['+currentDbType+']\x20Background\x20Jobs\x20Manager\x20stopped');return;}await jobManager['stop']();}__name(stopBackgroundJobs,'stopBackgroundJobs');async function createJobQueue(_0x3cd743,_0x1b5b04){if(!jobManager){logInfo('['+currentDbType+']\x20Creating\x20job\x20queue:\x20'+_0x3cd743);return;}await jobManager['createQueue'](_0x3cd743,_0x1b5b04);}__name(createJobQueue,'createJobQueue');async function addJobToQueue(_0x4aa91d,_0xa9ab92={}){if(!jobManager)return logInfo('['+currentDbType+']\x20Job\x20added\x20to\x20queue\x20\x27'+_0x4aa91d+'\x27\x20with\x20payload:\x20'+JSON['stringify'](_0xa9ab92)),emptyUuid;const _0x319824=await jobManager['send'](_0x4aa91d,_0xa9ab92);return _0x319824;}__name(addJobToQueue,'addJobToQueue');async function scheduleQueueExecution(_0x318fc1,_0x48ae67,_0x5c0067,_0x350515){if(!jobManager){logInfo('['+currentDbType+']\x20Scheduled\x20execution\x20for\x20\x27'+_0x318fc1+'\x27\x20('+_0x48ae67+')');return;}await jobManager['schedule'](_0x318fc1,_0x48ae67,_0x5c0067,_0x350515);}__name(scheduleQueueExecution,'scheduleQueueExecution');async function startQueueProcessing(_0x1d45e4,_0x4eca28,_0x5d195b){if(!jobManager){logInfo('['+currentDbType+']\x20Registered\x20worker\x20for\x20queue:\x20'+_0x1d45e4);return;}await jobManager['work'](_0x1d45e4,_0x4eca28,_0x5d195b);}__name(startQueueProcessing,'startQueueProcessing');async function publishEvent(_0x1ae1eb,_0x5592de){if(!jobManager){logInfo('['+currentDbType+']\x20Event\x20published\x20to\x20\x27'+_0x1ae1eb+'\x27:\x20'+JSON['stringify'](_0x5592de));return;}await jobManager['publish'](_0x1ae1eb,_0x5592de);}__name(publishEvent,'publishEvent');

export { addJobToQueue, createJobQueue, publishEvent, scheduleQueueExecution, startBackgroundJobs, startQueueProcessing, stopBackgroundJobs };
