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

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

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

    if (!scoresCol.fields.fieldNames().includes('penalty')) {
      scoresCol.fields.addAt(scoresCol.fields.length, new Field({
        hidden: false,
        id: 'text_penalty',
        max: 0,
        min: 0,
        name: 'penalty',
        pattern: '',
        presentable: false,
        primaryKey: false,
        required: false,
        system: false,
        type: 'text',
      }));
    }

    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);
  }
);

