const models       = require('../../models');
const responseUtil = require('./responseUtil');
const middleware   = require('../middleware');
const { check, oneOf } = require('express-validator/check');

module.exports = function(app, baseUrl) {
  var apiUrl = baseUrl + '/events';

  /**

   */
  app.post(
    apiUrl,
    [
      middleware.authenticateDevice,
      middleware.getEventDetailById.optional(),
      oneOf([
        check("eventDetailId").exists(),
        check("type").exists(),
      ], "Either 'eventDetailId' or 'type' must be specified"),
    ],
    middleware.requestWrapper(async (request, response) => {

      var detailsId = request.body.eventDetailId
      if (!detailsId) {
        var existingMatchingDetail = await models.EventDetail.getMatching(request.body.type, request.body.details);
        if (existingMatchingDetail) {
          detailsId = existingMatchingDetail.id;
        }
        else {
          var newDetails = await models.EventDetail.create({
            type: request.body.type,
            details: request.body.details,
          });
          detailsId = newDetails.id;
        }
      }

      newEvent = await models.Event.create({
        DeviceId: request.device.id,
        EventDetailId: detailsId,
        eventDateTime: request.body.eventDateTime
      });

      return responseUtil.send(response, {
        statusCode: 200,
        success: true,
        messages: ['Added event.'],
        eventId: newEvent.id,
        eventDetailId: detailsId,
      });
    })
  );


  // app.get(
  //   apiUrl,
  //   [
  //   ],
  //   middleware.requestWrapper(async (request, response) => {
  //     var devices = await models.EventDetails.allForUser(request.user);
  //     return responseUtil.send(response, {
  //       devices: devices,
  //       statusCode: 200,
  //       success: true,
  //       messages: ["completed get devices query"],
  //     });
  //   })
  // );
};
@@ -1529,409 +1529,6 @@
  );%0A
-%0A%0A  // app.get(%0A  //   apiUrl,%0A  //   %5B%0A  //   %5D,%0A  //   middleware.requestWrapper(async (request, response) =%3E %7B%0A  //     var devices = await models.EventDetails.allForUser(request.user);%0A  //     return responseUtil.send(response, %7B%0A  //       devices: devices,%0A  //       statusCode: 200,%0A  //       success: true,%0A  //       messages: %5B%22completed get devices query%22%5D,%0A  //     %7D);%0A  //   %7D)%0A  // );%0A
 %7D;

Remove unfinished code