/// <reference path="../pb_data/types.d.ts" />
migrate(
  app => {
    const scoresCol = app.findCollectionByNameOrId('pbc_809716240');

    if (!scoresCol.fields.fieldNames().includes('penaltyPoints')) {
      scoresCol.fields.addAt(scoresCol.fields.length, new Field({
        hidden: false,
        id: 'number_penaltyPoints',
        max: null,
        min: 0,
        name: 'penaltyPoints',
        onlyInt: true,
        presentable: false,
        required: false,
        system: false,
        type: 'number',
      }));
    }

    return app.save(scoresCol);
  },
  app => {
    const scoresCol = app.findCollectionByNameOrId('pbc_809716240');

    if (scoresCol.fields.fieldNames().includes('penaltyPoints')) {
      scoresCol.fields.removeByName('penaltyPoints');
    }

    return app.save(scoresCol);
  }
);
