const routes = require('express').Router();

const { isAdministratorUser, isOptionalUser, isLoggedUser } = require('../../middlewares/accessValidator');
const SchemaValidator = require('../../middlewares/schemaValidator');
const PaginateMiddleware = require('../../middlewares/paginate');
const FieldMiddleware = require('../../middlewares/fields');
const SortMiddleware = require('../../middlewares/sort');
const notificationController = require('./notification.controller');
const { pushSendEvent, deviceTokenInputType } = require('./notification.validations');

const generalInvalidFields = [
    'createdAt', 'updatedAt',
];

routes.get('/admin/notifications',
    isAdministratorUser,
    FieldMiddleware.middleware({
        invalidFields: generalInvalidFields
    }),
    SortMiddleware.middleware({ default: "-date" }),
    PaginateMiddleware.middleware(),
    notificationController.find({
        scopes: ['defaultScope']
    })
);

routes.get('/admin/notifications/:id',
    isAdministratorUser,
    FieldMiddleware.middleware({
        invalidFields: generalInvalidFields
    }),
    notificationController.findOne({
        scopes: ['defaultScope']
    })
);

routes.post('/admin/notifications',
    isAdministratorUser,
    SchemaValidator(pushSendEvent, true),
    notificationController.sendNotification({
        scopes: ['defaultScope']
    })
);

/*routes.post('/admin/notifications/event',
    isAdministratorUser,
    SchemaValidator(pushSendEvent, true),
    notificationController.sendNotificationEvent
);*/

/* Borrar cuando ya no aparezca la versión 1.0.10 */
/*routes.post('/notifications/register',
    isLoggedUser,
    SchemaValidator(deviceTokenInputType, true), 
    notificationController.registerDevice()
);*/

routes.post('/notifications/devices',
    isOptionalUser,
    SchemaValidator(deviceTokenInputType, true),
    notificationController.registerDevice()
);

module.exports = routes;