import './notif-job';
import { initializeAllStores } from '../stores/store-initializer';
import { startOrderHandler, startCancellationHandler, publishOrder } from './post-order-handler';
import { deleteOrders } from './delete-orders';

/**
 * Initialize all application services
 * This function handles initialization of:
 * - Role Manager (fetches and caches all roles)
 * - Const Store (syncs constants from DB to Redis)
 * - Post Order Handler (Redis Pub/Sub subscriber)
 * - Cancellation Handler (Redis Pub/Sub subscriber for order cancellations)
 * - Other services can be added here in the future
 */
export const initFunc = async (): Promise<void> => {
  try {
    console.log('Starting application initialization...');

    await Promise.all([
      initializeAllStores(),
      startOrderHandler(),
      startCancellationHandler(),
    ]);

    console.log('Application initialization completed successfully');
  } catch (error) {
    console.error('Application initialization failed:', error);
    throw error;
  }
};

export default initFunc;
