/// <reference path="../pb_data/types.d.ts" />
// Recreates the test_results collection (previously called quiz_results, which
// was dropped in 1780800001_deleted_legacy_collections.js). Stores one record
// per user per week containing their quiz score, answer breakdown, and points
// earned. Used by testService.saveTestResult / getTestResult.
migrate((app) => {
  const collection = new Collection({
    "createRule": "",
    "deleteRule": "",
    "listRule":   "",
    "updateRule": "",
    "viewRule":   "",
    "name": "test_results",
    "type": "base",
    "fields": [
      {
        "autogeneratePattern": "",
        "hidden": false,
        "id": "text_user_id",
        "max": 0,
        "min": 0,
        "name": "user_id",
        "pattern": "",
        "presentable": false,
        "primaryKey": false,
        "required": true,
        "system": false,
        "type": "text"
      },
      {
        "hidden": false,
        "id": "number_week_number",
        "max": null,
        "min": null,
        "name": "week_number",
        "onlyInt": true,
        "presentable": false,
        "required": true,
        "system": false,
        "type": "number"
      },
      {
        "hidden": false,
        "id": "number_score",
        "max": null,
        "min": null,
        "name": "score",
        "onlyInt": false,
        "presentable": false,
        "required": false,
        "system": false,
        "type": "number"
      },
      {
        "hidden": false,
        "id": "number_total",
        "max": null,
        "min": null,
        "name": "total",
        "onlyInt": false,
        "presentable": false,
        "required": false,
        "system": false,
        "type": "number"
      },
      {
        "hidden": false,
        "id": "number_percentage",
        "max": null,
        "min": null,
        "name": "percentage",
        "onlyInt": false,
        "presentable": false,
        "required": false,
        "system": false,
        "type": "number"
      },
      {
        "hidden": false,
        "id": "number_time_used",
        "max": null,
        "min": null,
        "name": "time_used",
        "onlyInt": false,
        "presentable": false,
        "required": false,
        "system": false,
        "type": "number"
      },
      {
        "autogeneratePattern": "",
        "hidden": false,
        "id": "text_completed_at",
        "max": 0,
        "min": 0,
        "name": "completed_at",
        "pattern": "",
        "presentable": false,
        "primaryKey": false,
        "required": false,
        "system": false,
        "type": "text"
      },
      {
        "hidden": false,
        "id": "json_breakdown",
        "maxSize": 0,
        "name": "breakdown",
        "presentable": false,
        "required": false,
        "system": false,
        "type": "json"
      },
      {
        "hidden": false,
        "id": "number_points_earned",
        "max": null,
        "min": null,
        "name": "points_earned",
        "onlyInt": false,
        "presentable": false,
        "required": false,
        "system": false,
        "type": "number"
      }
    ]
  });

  return app.save(collection);
}, (app) => {
  const collection = app.findCollectionByNameOrId("test_results");
  return app.delete(collection);
});
