import type { IServiceContainer } from '@stock-bot/handlers';
import { getLogger } from '@stock-bot/logger';
import type { JobPayload } from '../../../types/job-payloads';

const logger = getLogger('sync-status');

export async function getSyncStatus(
  payload: JobPayload,
  container: IServiceContainer
): Promise<Record<string, unknown>[]> {
  logger.info('Getting sync status...');

  try {
    const postgresClient = container.postgres;
    const query = 'SELECT * FROM sync_status ORDER BY provider, data_type';
    const result = await postgresClient.query(query);

    logger.info(`Retrieved sync status for ${result.rows.length} entries`);
    return result.rows;
  } catch (error) {
    logger.error('Failed to get sync status', { error });
    throw error;
  }
}
