import '@blocklet/sdk/lib/error-handler';

import dotenv from 'dotenv-flow';

import { ensurePaymentStats } from '../crons/payment-stat';
import { initPaywallResources } from '../libs/resource';
import { initialize } from '../store/models';
import { sequelize } from '../store/sequelize';

dotenv.config({ silent: true });

(async () => {
  try {
    initialize(sequelize);
    await initPaywallResources();
    await ensurePaymentStats();
    process.exit(0);
  } catch (err) {
    console.error('pre-start error', err);
    process.exit(1);
  }
})();
