import { Meteor } from 'meteor/meteor';
import { moment } from 'meteor/momentjs:moment';
import { Spendings } from '../../api/spendings/spendings.js';

Meteor.startup(() => {
  const getDateByDays = days => moment().add(days, 'days').toDate();

  if (Spendings.find().count() === 0) {
    const data = [
      {
        type: 'Luxury',
        amount: 3000,
        createdAt: getDateByDays(0),
      },
      {
        type: 'Food',
        amount: 230,
        createdAt: getDateByDays(-7),
      },
      {
        type: 'Personal investment',
        amount: 9700,
        createdAt: getDateByDays(-25),
      },
      {
        type: 'Subscription fees',
        amount: 220,
        createdAt: getDateByDays(-60),
      },
    ];

    data.forEach(spending => Spendings.insert(spending));
  }
});
